# File lib/numerizer.rb, line 109
  def self.numerize(string)
    string = string.dup

    # preprocess
    string.gsub!(/ +|([^\d])-([^\d])/, '\1 \2') # will mutilate hyphenated-words

    # easy/direct replacements
    (DIRECT_NUMS + SINGLE_NUMS).each do |dn|
      string.gsub!(/(^|\W)#{dn[0]}(?=$|\W)/i, '\1<num>' + dn[1].to_s)
    end

    # ten, twenty, etc.
    TEN_PREFIXES.each do |tp|
      SINGLE_NUMS.each do |dn|
        string.gsub!(/(^|\W)#{tp[0]}#{dn[0]}(?=$|\W)/i, '\1<num>' + (tp[1] + dn[1]).to_s)
      end
      SINGLE_ORDINALS.each do |dn|
        string.gsub!(/(^|\W)#{tp[0]}(\s)?#{dn[0]}(?=$|\W)/i, '\1<num>' + (tp[1] + dn[1]).to_s + dn[0][-2, 2])
      end
      string.gsub!(/(^|\W)#{tp[0]}(?=$|\W)/i, '\1<num>' + tp[1].to_s)
    end

    # handle fractions
    FRACTIONS.each do |tp|
      string.gsub!(/a #{tp[0]}(?=$|\W)/i, '<num>1/' + tp[1].to_s)
      string.gsub!(/\s#{tp[0]}(?=$|\W)/i, '/' + tp[1].to_s)
    end

    (DIRECT_ORDINALS + SINGLE_ORDINALS).each do |on|
      string.gsub!(/(^|\W)#{on[0]}(?=$|\W)/i, '\1<num>' + on[1].to_s + on[0][-2, 2])
    end

    # evaluate fractions when preceded by another number
    string.gsub!(/(\d+)(?: | and |-)+(<num>|\s)*(\d+)\s*\/\s*(\d+)/i) { ($1.to_f + ($3.to_f/$4.to_f)).to_s }

    # hundreds, thousands, millions, etc.
    BIG_PREFIXES.each do |bp|
      string.gsub!(/(?:<num>)?(\d*) *#{bp[0]}/i) { $1.empty? ? bp[1] : '<num>' + (bp[1] * $1.to_i).to_s }
      andition(string)
    end

    andition(string)

    string.gsub(/<num>/, '')
  end