Class: Rich::Pluralization::Inflector::Inflections

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rich/pluralization/inflector/inflections.rb

Defined Under Namespace

Classes: Inflection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInflections

Returns a new instance of Inflections.



12
13
14
# File 'lib/rich/pluralization/inflector/inflections.rb', line 12

def initialize
  set_attrs
end

Instance Attribute Details

#irregularsObject (readonly)

Returns the value of attribute irregulars.



9
10
11
# File 'lib/rich/pluralization/inflector/inflections.rb', line 9

def irregulars
  @irregulars
end

#locale=(value) ⇒ Object (writeonly)

Sets the attribute locale

Parameters:

  • value

    the value to set the attribute locale to.



10
11
12
# File 'lib/rich/pluralization/inflector/inflections.rb', line 10

def locale=(value)
  @locale = value
end

#pluralsObject (readonly)

Returns the value of attribute plurals.



9
10
11
# File 'lib/rich/pluralization/inflector/inflections.rb', line 9

def plurals
  @plurals
end

#singularsObject (readonly)

Returns the value of attribute singulars.



9
10
11
# File 'lib/rich/pluralization/inflector/inflections.rb', line 9

def singulars
  @singulars
end

#uncountablesObject (readonly)

Returns the value of attribute uncountables.



9
10
11
# File 'lib/rich/pluralization/inflector/inflections.rb', line 9

def uncountables
  @uncountables
end

Instance Method Details

#dumpObject



42
43
44
45
46
47
48
# File 'lib/rich/pluralization/inflector/inflections.rb', line 42

def dump
  puts "SINGULARS   : #{@singulars   .inspect}"
  puts "PLURAL      : #{@plurals     .inspect}"
  puts "IRREGULARS  : #{@irregulars  .inspect}"
  puts "UNCOUNTABLES: #{@uncountables.inspect}"
  puts "LOCALE      : #{@locale      .inspect}"
end

#irregular(*args) ⇒ Object



32
33
34
35
# File 'lib/rich/pluralization/inflector/inflections.rb', line 32

def irregular(*args)
  locale, s, pl = extract_args(*args)
  (@irregulars[locale] ||= {})[s.to_s] = pl
end

#plural(*args) ⇒ Object



28
29
30
# File 'lib/rich/pluralization/inflector/inflections.rb', line 28

def plural(*args)
  add_inflection :plurals  , *args
end

#set_attrsObject Also known as: reset_attrs



16
17
18
19
20
21
# File 'lib/rich/pluralization/inflector/inflections.rb', line 16

def set_attrs
  %w(singulars plurals irregulars uncountables).each do |x|
    instance_variable_set :"@#{x}", {}
  end
  @locale = I18n.default_locale
end

#singular(*args) ⇒ Object



24
25
26
# File 'lib/rich/pluralization/inflector/inflections.rb', line 24

def singular(*args)
  add_inflection :singulars, *args
end

#uncountable(*args) ⇒ Object



37
38
39
40
# File 'lib/rich/pluralization/inflector/inflections.rb', line 37

def uncountable(*args)
  locale, words = extract_args(*args)
  (@uncountables[locale] ||= []).concat [words].flatten
end