Class: Rich::Pluralization::Inflector::Inflections
- Inherits:
-
Object
- Object
- Rich::Pluralization::Inflector::Inflections
- Includes:
- Singleton
- Defined in:
- lib/rich/pluralization/inflector/inflections.rb
Defined Under Namespace
Classes: Inflection
Instance Attribute Summary collapse
-
#irregulars ⇒ Object
readonly
Returns the value of attribute irregulars.
-
#locale ⇒ Object
writeonly
Sets the attribute locale.
-
#plurals ⇒ Object
readonly
Returns the value of attribute plurals.
-
#singulars ⇒ Object
readonly
Returns the value of attribute singulars.
-
#uncountables ⇒ Object
readonly
Returns the value of attribute uncountables.
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize ⇒ Inflections
constructor
A new instance of Inflections.
- #irregular(*args) ⇒ Object
- #plural(*args) ⇒ Object
- #set_attrs ⇒ Object (also: #reset_attrs)
- #singular(*args) ⇒ Object
- #uncountable(*args) ⇒ Object
Constructor Details
#initialize ⇒ Inflections
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
#irregulars ⇒ Object (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
10 11 12 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 10 def locale=(value) @locale = value end |
#plurals ⇒ Object (readonly)
Returns the value of attribute plurals.
9 10 11 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 9 def plurals @plurals end |
#singulars ⇒ Object (readonly)
Returns the value of attribute singulars.
9 10 11 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 9 def singulars @singulars end |
#uncountables ⇒ Object (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
#dump ⇒ Object
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_attrs ⇒ Object 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 |