Class: Rich::Pluralization::Inflector::Inflections::Inflection
- Inherits:
-
Struct
- Object
- Struct
- Rich::Pluralization::Inflector::Inflections::Inflection
- Defined in:
- lib/rich/pluralization/inflector/inflections.rb
Instance Attribute Summary collapse
-
#exceptions ⇒ Object
readonly
Returns the value of attribute exceptions.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Class Method Summary collapse
Instance Method Summary collapse
- #exception?(word) ⇒ Boolean
- #inflect(word) ⇒ Object
- #inflect!(word) ⇒ Object
- #inspect ⇒ Object
- #match?(word, pattern) ⇒ Boolean
- #to_hash ⇒ Object
Instance Attribute Details
#exceptions ⇒ Object
Returns the value of attribute exceptions
72 73 74 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 72 def exceptions @exceptions end |
#rule ⇒ Object
Returns the value of attribute rule
72 73 74 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 72 def rule @rule end |
Class Method Details
.build(*args) ⇒ Object
74 75 76 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 74 def self.build(*args) self.new *(args.first.is_a?(Hash) ? args.first.values_at(*%w(rule replacement exceptions)) : args) end |
Instance Method Details
#exception?(word) ⇒ Boolean
86 87 88 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 86 def exception?(word) exceptions.any?{|e| match?(word, e)} end |
#inflect(word) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 95 def inflect(word) if exception?(word) word else rule.split(",").collect do |x| word.dup.gsub! parse_pattern(x, true), self[:replacement] end.detect{|x| !x.nil?} || word end end |
#inflect!(word) ⇒ Object
105 106 107 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 105 def inflect!(word) (result = inflect(word)) == word ? nil : result end |
#inspect ⇒ Object
109 110 111 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 109 def inspect to_hash.inspect end |
#match?(word, pattern) ⇒ Boolean
90 91 92 93 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 90 def match?(word, pattern) w, p = word.downcase, parse_pattern(pattern) p.is_a?(Regexp) ? !!w.match(p) : (w == p) end |
#to_hash ⇒ Object
113 114 115 |
# File 'lib/rich/pluralization/inflector/inflections.rb', line 113 def to_hash Hash[*members.zip(values).flatten] end |