class Strings::Inflection::Configuration
Attributes
plurals[R]
singulars[R]
uncountables[R]
Public Class Methods
new()
click to toggle source
Initialize a configuration
@api private
# File lib/strings/inflection/configuration.rb, line 12 def initialize reset end
Public Instance Methods
clear(name)
click to toggle source
# File lib/strings/inflection/configuration.rb, line 79 def clear(name) instance_variable_set "@#{name}", { noun: [], verb: [] } end
plural(rule, replacement, term: :noun)
click to toggle source
Add a plural rule form for a term. By default noun.
@example
plural "index", "indexes"
@param [String,Regex] rule @param [String] replacement
@api public
# 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)
click to toggle source
Reset configuration and remove loaded inflections. By default all scopes are reset. The available scopes are: :plurals, :singulars, :uncountable
@example
reset(:all) reset(:plurals)
@api public
# 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)
click to toggle source
Add a rule that provides transformation for both singular and plural inflections.
@example
rule "ax", "axes"
@api public
# 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)
click to toggle source
Add a singular rule form for a term. By default noun.
@example
singular "axes", "ax"
@param [String,Regex] rule @param [String] replacement
@api public
# 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)
click to toggle source
Add an uncountable word. By default noun.
@api public
# File lib/strings/inflection/configuration.rb, line 57 def uncountable(word, term: :noun) @uncountables[term] << word end