Class: Strings::Inflection::Noun

Inherits:
Term
  • Object
show all
Defined in:
lib/strings/inflection/noun.rb

Instance Attribute Summary

Attributes inherited from Term

#word

Instance Method Summary collapse

Methods inherited from Term

[], #find_match, #initialize, #plural?, #singular?, #to_s

Constructor Details

This class inherits a constructor from Strings::Inflection::Term

Instance Method Details

#+(other_word) ⇒ CombinedNoun

Combine this noun with another word

Parameters:

  • other_word (String)

    the other word to combined with

Returns:



65
66
67
# File 'lib/strings/inflection/noun.rb', line 65

def +(other_word)
  CombinedNoun.new([word, other_word])
end

#pluralObject

Inflect a word to its plural form

Examples:

Strings::Inflection::Noun.new("error").plural
# => "errors"

Parameters:

  • word (String)

    noun to inflect to plural form



50
51
52
53
54
55
# File 'lib/strings/inflection/noun.rb', line 50

def plural
  return word if word.to_s.empty?

  find_match(Inflection.configuration.plurals[:noun]) ||
    (uncountable? && word) || find_match(Nouns.plurals) || word
end

#singularObject

Inflect a word to its singular form

Examples:

Strings::Inflection::Noun.new("errors").singular
# => "error"

Parameters:

  • word (String)

    the noun to inflect to singular form



33
34
35
36
37
38
# File 'lib/strings/inflection/noun.rb', line 33

def singular
  return word if word.to_s.empty?

  find_match(Inflection.configuration.singulars[:noun]) ||
    (uncountable? && word) || find_match(Nouns.singulars) || word
end

#uncountable?Boolean

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.

Check if word is uncountable

Parameters:

  • word (String)

    the word to check

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/strings/inflection/noun.rb', line 18

def uncountable?
  Inflection.configuration.uncountables[:noun].include?(word.downcase) ||
    Nouns.uncountable.include?(word.downcase)
end