Class: Strings::Inflection::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/strings/inflection/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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

#pluralsObject (readonly)

Returns the value of attribute plurals.



7
8
9
# File 'lib/strings/inflection/configuration.rb', line 7

def plurals
  @plurals
end

#singularsObject (readonly)

Returns the value of attribute singulars.



7
8
9
# File 'lib/strings/inflection/configuration.rb', line 7

def singulars
  @singulars
end

#uncountablesObject (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.

Examples:

plural "index", "indexes"

Parameters:

  • rule (String, Regex)
  • replacement (String)


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

Examples:

reset(:all)
reset(:plurals)


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.

Examples:

rule "ax", "axes"


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.

Examples:

singular "axes", "ax"

Parameters:

  • rule (String, Regex)
  • replacement (String)


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