Class: Alexa::TrafficHistory::HistoricalData

Inherits:
Object
  • Object
show all
Includes:
Container
Defined in:
lib/alexa/traffic_history/historical_data.rb

Instance Attribute Summary

Attributes included from Container

#data

Instance Method Summary collapse

Methods included from Container

included, #keys, #method_missing, #to_mongo

Constructor Details

#initialize(xml_node = nil) ⇒ HistoricalData

Returns a new instance of HistoricalData.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/alexa/traffic_history/historical_data.rb', line 8

def initialize(xml_node = nil)
  @data = {}

  if ! xml_node.nil?
    xml_node.xpath('Data').each do |d|
      day = d.xpath('Date').text.strip

      ddata = {}
      ddata[:date] = day
      ddata[:pageviews_permillion] = d.xpath('PageViews/PerMillion').text.strip
      ddata[:pageviews_peruser] = d.xpath('PageViews/PerUser').text.strip
      ddata[:rank] = d.xpath('Rank').text.strip
      ddata[:reach_permillion] = d.xpath('Reach/PerMillion').text.strip

      @data[day] = ddata
    end
  end

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Alexa::Container