Module: Inform::Plurals
- Included in:
- Inform
- Defined in:
- lib/runtime/plurals.rb
Overview
The Plurals module
Instance Method Summary collapse
-
#apply_inflections(word, rules) ⇒ Object
Applies inflection rules for
singularizeandpluralize. - #plural?(s) ⇒ Boolean
-
#pluralize(word, n = nil) ⇒ Object
Returns the plural form of the word in the string.
- #singular?(s) ⇒ Boolean
-
#singularize(word) ⇒ Object
The reverse of
pluralize, returns the singular form of a word in a string.
Instance Method Details
#apply_inflections(word, rules) ⇒ Object
Applies inflection rules for singularize and pluralize.
48 49 50 51 52 53 54 55 56 |
# File 'lib/runtime/plurals.rb', line 48 def apply_inflections(word, rules) return "" if word.empty? result = word.to_s.dup return result if Inform::Inflector.inflections.uncountables.include?(result.downcase[/\b\w+\Z/]) for (rule, replacement) in rules break if result.sub!(rule, replacement) end result end |
#plural?(s) ⇒ Boolean
43 44 45 |
# File 'lib/runtime/plurals.rb', line 43 def plural?(s) pluralize(s) == s end |
#pluralize(word, n = nil) ⇒ Object
Returns the plural form of the word in the string.
28 29 30 31 |
# File 'lib/runtime/plurals.rb', line 28 def pluralize(word, n = nil) return word if n == 1 apply_inflections(word, Inform::Inflector.inflections.plurals) end |
#singular?(s) ⇒ Boolean
39 40 41 |
# File 'lib/runtime/plurals.rb', line 39 def singular?(s) singularize(s) == s end |
#singularize(word) ⇒ Object
The reverse of pluralize, returns the singular form of a word in a string.
35 36 37 |
# File 'lib/runtime/plurals.rb', line 35 def singularize(word) apply_inflections(word, Inform::Inflector.inflections.singulars) end |