Class: ActiveSupport::Inflector::Inflections::Uncountables

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_support/inflector/inflections.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #compact_blank, #exclude?, #excluding, #in_order_of, #including, #index_by, #index_with, #many?, #maximum, #minimum, #pick, #pluck, #sole

Constructor Details

#initializeUncountables

Returns a new instance of Uncountables.



40
41
42
43
# File 'lib/active_support/inflector/inflections.rb', line 40

def initialize
  @members = []
  @pattern = nil
end

Instance Method Details

#<<(word) ⇒ Object



50
51
52
53
54
55
# File 'lib/active_support/inflector/inflections.rb', line 50

def <<(word)
  word = word.downcase
  @members << word
  @pattern = nil
  self
end

#add(words) ⇒ Object



61
62
63
64
65
66
# File 'lib/active_support/inflector/inflections.rb', line 61

def add(words)
  words = words.flatten.map(&:downcase)
  @members.concat(words)
  @pattern = nil
  self
end

#delete(entry) ⇒ Object



45
46
47
48
# File 'lib/active_support/inflector/inflections.rb', line 45

def delete(entry)
  @members.delete(entry)
  @pattern = nil
end

#flattenObject



57
58
59
# File 'lib/active_support/inflector/inflections.rb', line 57

def flatten
  @members.dup
end

#uncountable?(str) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/active_support/inflector/inflections.rb', line 68

def uncountable?(str)
  if @pattern.nil?
    members_pattern = Regexp.union(@members.map { |w| /#{Regexp.escape(w)}/i })
    @pattern = /\b#{members_pattern}\Z/i
  end
  @pattern.match?(str)
end