class Strings::Inflection::Term
Attributes
word[R]
Public Class Methods
[](word)
click to toggle source
Create a term
@api public
# File lib/strings/inflection/term.rb, line 9 def self.[](word) self.new(word) end
new(word)
click to toggle source
Create a new term
@param [String] word
the word to turn into a term object
@api public
# File lib/strings/inflection/term.rb, line 21 def initialize(word) @word = word.dup freeze end
Public Instance Methods
find_match(rules)
click to toggle source
Find a matching rule and replace
@return [nil, String]
nil or replaced word
@api private
# 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?()
click to toggle source
Check if noun is in plural form
@example
Strings::Inflection::Noun.new("errors").plural? # => true
@return [Boolean]
@api public
# File lib/strings/inflection/term.rb, line 64 def plural? return false if word.to_s.empty? word.downcase == plural end
singular?()
click to toggle source
Check if noun is in singular form
@example
Strings::Inflection::Noun.new("error").singular? # => true
@return [Boolean]
@api public
# File lib/strings/inflection/term.rb, line 49 def singular? return false if word.to_s.empty? word.downcase == singular end
to_s()
click to toggle source
A string representation of this term
@api public
# File lib/strings/inflection/term.rb, line 73 def to_s word.to_s end