class Indirizzo::NumberHelper

Public Class Methods

expand_numbers(string) click to toggle source

Expands a token into a list of possible strings based on the Geocoder::US::Name_Abbr constant, and expands numerals and number words into their possible equivalents.

# File lib/indirizzo/number_helper.rb, line 6
def self.expand_numbers (string)
  if /\b\d+(?:st|nd|rd|th)?\b/o.match string
    match = $&
      num = $&.to_i
  elsif Ordinals.regexp.match string
    num = Ordinals[$&]
    match = $&
  elsif Cardinals.regexp.match string
    num = Cardinals[$&]
    match = $&
  end
  strings = []
  if num and num < 100
    [num.to_s, Ordinals[num], Cardinals[num]].each {|replace|
      strings << string.sub(match, replace)
    }
  else
    strings << string
  end
  strings
end