Class: Strings::Inflection::Configuration
- Inherits:
-
Object
- Object
- Strings::Inflection::Configuration
- Defined in:
- lib/strings/inflection/configuration.rb
Instance Attribute Summary collapse
-
#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
- #clear(name) ⇒ Object
-
#initialize ⇒ Configuration
constructor
private
Initialize a configuration.
-
#plural(rule, replacement, term: :noun) ⇒ Object
Add a plural rule form for a term.
-
#reset(scope = :all) ⇒ Object
Reset configuration and remove loaded inflections.
-
#rule(sing, plur, term: :noun) ⇒ Object
Add a rule that provides transformation for both singular and plural inflections.
-
#singular(rule, replacement, term: :noun) ⇒ Object
Add a singular rule form for a term.
-
#uncountable(word, term: :noun) ⇒ Object
Add an uncountable word.
Constructor Details
#initialize ⇒ Configuration
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a configuration
12 13 14 |
# File 'lib/strings/inflection/configuration.rb', line 12 def initialize reset end |
Instance Attribute Details
#plurals ⇒ Object (readonly)
Returns the value of attribute plurals.
7 8 9 |
# File 'lib/strings/inflection/configuration.rb', line 7 def plurals @plurals end |
#singulars ⇒ Object (readonly)
Returns the value of attribute singulars.
7 8 9 |
# File 'lib/strings/inflection/configuration.rb', line 7 def singulars @singulars end |
#uncountables ⇒ Object (readonly)
Returns the value of attribute uncountables.
7 8 9 |
# File 'lib/strings/inflection/configuration.rb', line 7 def uncountables @uncountables end |
Instance Method Details
#clear(name) ⇒ Object
79 80 81 |
# File 'lib/strings/inflection/configuration.rb', line 79 def clear(name) instance_variable_set "@#{name}", { noun: [], verb: [] } end |
#plural(rule, replacement, term: :noun) ⇒ Object
Add a plural rule form for a term. By default noun.
38 39 40 |
# File 'lib/strings/inflection/configuration.rb', line 38 def plural(rule, replacement, term: :noun) @plurals[term] << [Regexp.new(rule, "i"), replacement] end |
#reset(scope = :all) ⇒ Object
Reset configuration and remove loaded inflections. By default all scopes are reset. The available scopes are: :plurals, :singulars, :uncountable
70 71 72 73 74 75 76 77 |
# File 'lib/strings/inflection/configuration.rb', line 70 def reset(scope = :all) case scope when :all %i[singulars plurals uncountables].map {|s| clear(s) } else clear(scope) end end |
#rule(sing, plur, term: :noun) ⇒ Object
Add a rule that provides transformation for both singular and plural inflections.
49 50 51 52 |
# File 'lib/strings/inflection/configuration.rb', line 49 def rule(sing, plur, term: :noun) plural(sing, plur, term: term) singular(plur, sing, term: term) end |
#singular(rule, replacement, term: :noun) ⇒ Object
Add a singular rule form for a term. By default noun.
25 26 27 |
# File 'lib/strings/inflection/configuration.rb', line 25 def singular(rule, replacement, term: :noun) @singulars[term] << [Regexp.new(rule, "i"), replacement] end |
#uncountable(word, term: :noun) ⇒ Object
Add an uncountable word. By default noun.
57 58 59 |
# File 'lib/strings/inflection/configuration.rb', line 57 def uncountable(word, term: :noun) @uncountables[term] << word end |