Class: Alexa::UrlInfo::Usage
- Inherits:
-
Object
- Object
- Alexa::UrlInfo::Usage
- Includes:
- Container
- Defined in:
- lib/alexa/url_info/usage.rb
Instance Attribute Summary
Attributes included from Container
Instance Method Summary collapse
-
#initialize(xml_node = nil) ⇒ Usage
constructor
A new instance of Usage.
Methods included from Container
included, #keys, #method_missing, #to_mongo
Constructor Details
#initialize(xml_node = nil) ⇒ Usage
Returns a new instance of Usage.
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 |
# File 'lib/alexa/url_info/usage.rb', line 6 def initialize(xml_node = nil) @data = {} if !xml_node.nil? xml_node.xpath('//UsageStatistic').each do |s| range_node = s.xpath('TimeRange').children.find_all { |c| c.name != 'text' }.first key = range_node.text.strip + ' ' + range_node.name.strip stats = {} stats[:rank_value] = s.xpath('Rank/Value').text.strip stats[:rank_delta] = s.xpath('Rank/Delta').text.strip stats[:reach_rank_value] = s.xpath('Reach/Rank/Value').text.strip stats[:reach_rank_delta] = s.xpath('Reach/Rank/Delta').text.strip stats[:reach_permillion_value] = s.xpath('Reach/PerMillion/Value').text.strip stats[:reach_permillion_delta] = s.xpath('Reach/PerMillion/Delta').text.strip stats[:pageviews_permillion_value] = s.xpath('PageViews/PerMillion/Value').text.strip stats[:pageviews_permillion_delta] = s.xpath('PageViews/PerMillion/Delta').text.strip stats[:pageviews_rank_value] = s.xpath('PageViews/Rank/Value').text.strip stats[:pageviews_rank_delta] = s.xpath('PageViews/Rank/Delta').text.strip stats[:pageviews_peruser_value] = s.xpath('PageViews/PerUser/Value').text.strip stats[:pageviews_peruser_delta] = s.xpath('PageViews/PerUser/Delta').text.strip @data[key] = stats end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Alexa::Container