Permalink
Browse files

Merge pull request #118 from truenorthservice/swap-tower.support.stri…

…ng-to-use-inflector-module

Made Tower.Support.String#pluralize and #singularize use Tower.modules.inflector
  • Loading branch information...
lancejpollard committed Apr 21, 2012
2 parents b7b4c55 + ae41dae commit 53d2933c91bb2e5f9363a8fb2b7091618ebd6e3e
Showing with 19 additions and 16 deletions.
  1. +3 −16 src/tower/support/string.coffee
  2. +16 −0 test/cases/support/stringTest.coffee
@@ -20,28 +20,15 @@ Tower.Support.String =
.replace('-', '_').toLowerCase()
singularize: (string) ->
- len = string.length
- if string.substr(len - 3) is 'ies'
- string.substr(0, len - 3) + 'y'
- else if string.substr(len - 1) is 's'
- string.substr(0, len - 1)
- else
- string
+ Tower.modules.inflector.singularize arguments...
pluralize: (count, string) ->
if string
return string if count is 1
else
string = count
-
- len = string.length
- lastLetter = string.substr(len - 1)
- if lastLetter is 'y'
- "#{string.substr(0, len - 1)}ies"
- else if lastLetter is 's'
- string
- else
- "#{string}s"
+
+ Tower.modules.inflector.pluralize string
capitalize: (string) -> string.replace @capitalize_rx, (m,p1,p2) -> p1 + p2.toUpperCase()
@@ -1,2 +1,18 @@
describe 'Tower.Support.String', ->
+ describe 'inflection', ->
+ support = Tower.Support.String
+
+ test 'pluralize', ->
+ assert.equal support.pluralize("entry"), "entries"
+ assert.equal support.pluralize("business"), "businesses"
+ assert.equal support.pluralize("people"), "people"
+ assert.equal support.pluralize("person"), "people"
+ assert.equal support.pluralize(2, "thing"), "things"
+ assert.equal support.pluralize(1, "thing"), "thing"
+ assert.equal support.pluralize(0, "thing"), "things"
+
+ test 'singularize', ->
+ assert.equal support.singularize("businesses"), "business"
+ assert.equal support.singularize("people"), "person"
+ assert.equal support.singularize("person"), "person"

0 comments on commit 53d2933

Please sign in to comment.