Class: ApipieBindings::Inflector
- Inherits:
-
Object
- Object
- ApipieBindings::Inflector
- Defined in:
- lib/apipie_bindings/inflector.rb
Class Method Summary collapse
- .apply_inflections(word, rules) ⇒ Object
- .inflections(locale = :en) ⇒ Object
- .pluralize(word, locale = :en) ⇒ Object
- .singularize(word, locale = :en) ⇒ Object
Class Method Details
.apply_inflections(word, rules) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/apipie_bindings/inflector.rb', line 102 def self.apply_inflections(word, rules) result = word.to_s.dup if word.empty? || inflections.uncountables.include?(result.downcase[/\b\w+\Z/]) result else rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) } result end end |
.inflections(locale = :en) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/apipie_bindings/inflector.rb', line 92 def self.inflections(locale = :en) if block_given? yield ApipieBindings::Inflections.instance(locale) else ApipieBindings::Inflections.instance(locale) end end |
.pluralize(word, locale = :en) ⇒ Object
84 85 86 |
# File 'lib/apipie_bindings/inflector.rb', line 84 def self.pluralize(word, locale = :en) apply_inflections(word, inflections(locale).plurals) end |
.singularize(word, locale = :en) ⇒ Object
88 89 90 |
# File 'lib/apipie_bindings/inflector.rb', line 88 def self.singularize(word, locale = :en) apply_inflections(word, inflections(locale).singulars) end |