class Pascoale::Inflector

Constants

PLURAL_RULES
SINGULAR_RULES

Public Class Methods

new(text) click to toggle source
# File lib/pascoale/inflector.rb, line 112
def initialize(text)
  @text = text
end

Public Instance Methods

pluralize() click to toggle source
# File lib/pascoale/inflector.rb, line 116
def pluralize
  @pluralized ||= apply_rules_to(@text, PLURAL_RULES)
end
singularize() click to toggle source
# File lib/pascoale/inflector.rb, line 120
def singularize
  @singularized ||= apply_rules_to(@text, SINGULAR_RULES)
end

Private Instance Methods

apply_rules_to(text, rules) click to toggle source
# File lib/pascoale/inflector.rb, line 125
def apply_rules_to(text, rules)
  rslt = text.dup
  rules.each do |regex, replace|
    reg = Regexp === regex ? regex : /^#{regex}$/
    case replace
      when Proc
        return rslt if rslt.sub!(reg, &replace)
      else
        return rslt if rslt.sub!(reg, replace)
    end
  end
  rslt
end