lib/quantcast_tools/page_reader.rb
def monthly_unique_visitors_us

         m_val = parsed_qc_html.css(".current").select{|c| c['profile-data'] == "-1"}[0].text.strip
         unless m_val.include? "N/A"
            #parse with regex, e.g. "3.2", "M"

            if m_matches = m_val.match(/(\d+\.?\d*)([\w]?)/)
               m_number, m_abbrev =  m_matches[1..2]
               multiplier = case m_abbrev
               when 'K'
                  1000
               when 'M'
                  1000000
               when 'B'
                  1000000000
               else
                  1
               end
               return (m_number.to_f * multiplier).to_i
            end

            
         end
      end
# The text bit looks like this:
# Monthly Uniques    67.4M US    291.1M Global
#
# returns: Integer, where M and K are translated to 1000000 and 1000, respectively
The text bit looks like this:
Monthly Uniques    67.4M US    291.1M Global

Integer, where M and K are translated to 1000000 and 1000, respectively
The text bit looks like this : Monthly Uniques 67 . 4M US 291 . 1M Global Integer where M and K are translated to 1000000 and 1000 respectively
def monthly_unique_visitors_us
         m_val = parsed_qc_html.css(".current").select{|c| c['profile-data'] == "-1"}[0].text.strip
         unless m_val.include? "N/A"
            if m_matches = m_val.match(/(\d+\.?\d*)([\w]?)/)
               m_number, m_abbrev =  m_matches[1..2]
               multiplier = case m_abbrev
               when 'K'
                  1000
               when 'M'
                  1000000
               when 'B'
                  1000000000
               else
                  1
               end
               return (m_number.to_f * multiplier).to_i
            end
         end
      end
def monthly_unique_visitors_us m_val = parsed_qc_html . css ( ".current" ) . select { | c | c [ 'profile-data' ] == "-1" } [ 0 ] . text . strip unless m_val . include? "N/A" if m_matches = m_val . match ( / ( \d + \. ? \d *)([ \w ]?) / ) m_number , m_abbrev = m_matches [ 1 .. 2 ] multiplier = case m_abbrev when 'K' 1000 when 'M' 1000000 when 'B' 1000000000 else 1 end return ( m_number . to_f * multiplier ) . to_i end end end
The text bit looks like this:
Monthly Uniques    67.4M US    291.1M Global
The text bit looks like this : Monthly Uniques 67 . 4M US 291 . 1M Global
#parse with regex, e.g. "3.2", "M"