Class: Alexa::UrlInfo::TrafficData
- Inherits:
-
Object
- Object
- Alexa::UrlInfo::TrafficData
- Includes:
- Container
- Defined in:
- lib/alexa/url_info/traffic_data.rb
Instance Attribute Summary
Attributes included from Container
Instance Method Summary collapse
-
#initialize(xml_node = nil) ⇒ TrafficData
constructor
A new instance of TrafficData.
Methods included from Container
included, #keys, #method_missing, #to_mongo
Constructor Details
#initialize(xml_node = nil) ⇒ TrafficData
Returns a new instance of TrafficData.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/alexa/url_info/traffic_data.rb', line 6 def initialize(xml_node = nil) @data = {} if !xml_node.nil? @data[:data_url] = xml_node.xpath('DataUrl').text.strip @data[:rank] = xml_node.xpath('Rank').text.strip @data[:by_country] = [] xml_node.xpath('RankByCountry/Country').each do |r| @data[:by_country] << { :country => r['Code'], :rank => r.xpath('Rank').text.strip, :page_views => r.xpath('Contribution/PageViews').text.strip, :users => r.xpath('Contribution/Users').text.strip, } end @data[:by_city] = [] xml_node.xpath('RankByCity/City').each do |c| @data[:by_city] << { :code => c['Code'], :name => c['Name'], :rank => c.xpath('Rank').text.strip, :page_views => c.xpath('Contribution/PageViews').text.strip, :users => c.xpath('Contribution/Users').text.strip, :average_page_views => c.xpath('Contribution/PerUser/AveragePageViews').text.strip, } end @data[:usage] = [] end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Alexa::Container