Class: Strings::Inflection::Term
- Inherits:
-
Object
- Object
- Strings::Inflection::Term
- Defined in:
- lib/strings/inflection/term.rb
Instance Attribute Summary collapse
-
#word ⇒ Object
readonly
Returns the value of attribute word.
Class Method Summary collapse
-
.[](word) ⇒ Object
Create a term.
Instance Method Summary collapse
-
#find_match(rules) ⇒ nil, String
private
Find a matching rule and replace.
-
#initialize(word) ⇒ Term
constructor
Create a new term.
-
#plural? ⇒ Boolean
Check if noun is in plural form.
-
#singular? ⇒ Boolean
Check if noun is in singular form.
-
#to_s ⇒ Object
A string representation of this term.
Constructor Details
#initialize(word) ⇒ Term
Create a new term
21 22 23 24 |
# File 'lib/strings/inflection/term.rb', line 21 def initialize(word) @word = word.dup freeze end |
Instance Attribute Details
#word ⇒ Object (readonly)
Returns the value of attribute word.
13 14 15 |
# File 'lib/strings/inflection/term.rb', line 13 def word @word end |
Class Method Details
.[](word) ⇒ Object
Create a term
9 10 11 |
# File 'lib/strings/inflection/term.rb', line 9 def self.[](word) self.new(word) end |
Instance Method Details
#find_match(rules) ⇒ nil, String
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.
Find a matching rule and replace
32 33 34 35 36 37 38 |
# File 'lib/strings/inflection/term.rb', line 32 def find_match(rules) regex, replacement = rules.find { |rule| !!(word =~ rule[0]) } return if regex.nil? word.sub(regex, replacement) end |
#plural? ⇒ Boolean
Check if noun is in plural form
64 65 66 67 68 |
# File 'lib/strings/inflection/term.rb', line 64 def plural? return false if word.to_s.empty? word.downcase == plural end |
#singular? ⇒ Boolean
Check if noun is in singular form
49 50 51 52 53 |
# File 'lib/strings/inflection/term.rb', line 49 def singular? return false if word.to_s.empty? word.downcase == singular end |
#to_s ⇒ Object
A string representation of this term
73 74 75 |
# File 'lib/strings/inflection/term.rb', line 73 def to_s word.to_s end |