Module: Prick::Inflector

Defined in:
lib/prick-inflector.rb,
lib/prick-inflector/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.plural?(word) ⇒ Boolean

#plural? is defined using #singularize because #pluralize would cause endless recursion

Returns:

  • (Boolean)


36
37
38
# File 'lib/prick-inflector.rb', line 36

def self.plural?(word)
  singularize(word) != word
end

.pluralize(word) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/prick-inflector.rb', line 12

def self.pluralize(word)
  return word if plural? word
  result = @@inflector.pluralize(word)
  if result == word
    word =~ /s$/ ? "#{word}es" : "#{word}s"
  else
    result
  end
end

.singular?(word) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/prick-inflector.rb', line 40

def self.singular?(word)
  singularize(word) == word
end

.singularize(word) ⇒ Object

Note that DryInflector::singularize handles the special PgGraph pluralization rules by default



24
25
26
27
28
29
30
31
32
# File 'lib/prick-inflector.rb', line 24

def self.singularize(word)
  if word == "s" # Dry::Inflector return an empty string
    "s"
  elsif word =~ /^(.*s)es$/ && pluralize($1) == word
    $1
  else
    @@inflector.singularize(word)
  end
end