Module: Volt::Inflector
- Defined in:
- lib/volt/extra_core/inflector/methods.rb,
lib/volt/extra_core/inflector/inflections.rb
Defined Under Namespace
Classes: Inflections
Class Method Summary collapse
-
.inflections(locale = :en) ⇒ Object
Yields a singleton instance of Inflector::Inflections so you can specify additional inflector rules.
-
.pluralize(word, locale = :en) ⇒ Object
Returns the plural form of the word in the string.
-
.singularize(word, locale = :en) ⇒ Object
The reverse of
pluralize
, returns the singular form of a word in a string.
Class Method Details
.inflections(locale = :en) ⇒ Object
Yields a singleton instance of Inflector::Inflections so you can specify additional inflector rules. If passed an optional locale, rules for other languages can be specified. If not specified, defaults to :en
. Only rules for English are provided.
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.uncountable 'rails'
end
205 206 207 208 209 210 211 |
# File 'lib/volt/extra_core/inflector/inflections.rb', line 205 def self.inflections(locale = :en) if block_given? yield Inflections.instance(locale) else Inflections.instance(locale) end end |
.pluralize(word, locale = :en) ⇒ Object
Returns the plural form of the word in the string.
If passed an optional locale
parameter, the word will be pluralized using rules defined for that language. By default, this parameter is set to :en
.
'post'.pluralize # => "posts"
'octopus'.pluralize # => "octopi"
'sheep'.pluralize # => "sheep"
'words'.pluralize # => "words"
'CamelOctopus'.pluralize # => "CamelOctopi"
'ley'.pluralize(:es) # => "leyes"
21 22 23 |
# File 'lib/volt/extra_core/inflector/methods.rb', line 21 def self.pluralize(word, locale = :en) apply_inflections(word, inflections(locale).plurals) end |
.singularize(word, locale = :en) ⇒ Object
The reverse of pluralize
, returns the singular form of a word in a string.
If passed an optional locale
parameter, the word will be pluralized using rules defined for that language. By default, this parameter is set to :en
.
'posts'.singularize # => "post"
'octopi'.singularize # => "octopus"
'sheep'.singularize # => "sheep"
'word'.singularize # => "word"
'CamelOctopi'.singularize # => "CamelOctopus"
'leyes'.singularize(:es) # => "ley"
38 39 40 |
# File 'lib/volt/extra_core/inflector/methods.rb', line 38 def self.singularize(word, locale = :en) apply_inflections(word, inflections(locale).singulars) end |