Class: Frontline::Inflector::Inflections

Inherits:
Object
  • Object
show all
Defined in:
lib/frontline/inflect.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInflections

Returns a new instance of Inflections.



14
15
16
# File 'lib/frontline/inflect.rb', line 14

def initialize
  @plurals, @singulars, @uncountables = [], [], []
end

Instance Attribute Details

#pluralsObject (readonly)

Returns the value of attribute plurals.



12
13
14
# File 'lib/frontline/inflect.rb', line 12

def plurals
  @plurals
end

#singularsObject (readonly)

Returns the value of attribute singulars.



12
13
14
# File 'lib/frontline/inflect.rb', line 12

def singulars
  @singulars
end

#uncountablesObject (readonly)

Returns the value of attribute uncountables.



12
13
14
# File 'lib/frontline/inflect.rb', line 12

def uncountables
  @uncountables
end

Class Method Details

.instance(locale = :en) ⇒ Object



8
9
10
# File 'lib/frontline/inflect.rb', line 8

def self.instance(locale = :en)
  @__instance__[locale] ||= new
end

Instance Method Details

#plural(rule, replacement) ⇒ Object

Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression. The replacement should always be a string that may include references to the matched data from the rule.



22
23
24
25
26
# File 'lib/frontline/inflect.rb', line 22

def plural(rule, replacement)
  @uncountables.delete(rule) if rule.is_a?(String)
  @uncountables.delete(replacement)
  @plurals.unshift([rule, replacement])
end

#singular(rule, replacement) ⇒ Object

Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression. The replacement should always be a string that may include references to the matched data from the rule.



32
33
34
35
36
# File 'lib/frontline/inflect.rb', line 32

def singular(rule, replacement)
  @uncountables.delete(rule) if rule.is_a?(String)
  @uncountables.delete(replacement)
  @singulars.unshift([rule, replacement])
end

#uncountable(*words) ⇒ Object

Add uncountable words that shouldn’t be attempted inflected.

uncountable 'money'
uncountable 'money', 'information'
uncountable %w( money information rice )


43
44
45
# File 'lib/frontline/inflect.rb', line 43

def uncountable(*words)
  (@uncountables << words).flatten!
end