class Indirizzo::NumberMap

The NumberMap class provides a means for mapping ordinal and cardinal number words to digits and back.

Attributes

regexp[RW]

Public Class Methods

[](array) click to toggle source
# File lib/indirizzo/numbers.rb, line 6
def self.[] (array)
  nmap = self.new({})
  array.each {|item| nmap << item } 
  nmap.build_match
  nmap
end
new(array) click to toggle source
# File lib/indirizzo/numbers.rb, line 12
def initialize (array)
  @count = 0
end

Public Instance Methods

<<(item) click to toggle source
# File lib/indirizzo/numbers.rb, line 23
def <<(item)
  store clean(item), @count
  store @count, item
  @count += 1
end
[](key) click to toggle source
Calls superclass method
# File lib/indirizzo/numbers.rb, line 28
def [] (key)
  super(clean(key))
end
build_match() click to toggle source
# File lib/indirizzo/numbers.rb, line 15
def build_match
  @regexp = Regexp.new(
    '\b(' + keys.flatten.join("|") + ')\b',
    Regexp::IGNORECASE)
end
clean(key) click to toggle source
# File lib/indirizzo/numbers.rb, line 20
def clean (key)
  key.is_a?(String) ? key.downcase.gsub(/\W/o, "") : key
end