Class: Alexa::UrlInfo::ContributingSubdomains

Inherits:
Object
  • Object
show all
Includes:
Container
Defined in:
lib/alexa/url_info/contributing_subdomains.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) ⇒ ContributingSubdomains

Returns a new instance of ContributingSubdomains.



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

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

  if !xml_node.nil?
    xml_node.xpath('ContributingSubdomain').each do |cs|
      range_node = cs.xpath('TimeRange').children.find_all { |c| c.name != 'text' }.first

      domain = cs.xpath('DataUrl').text.strip

      ddata = {}

      ddata[:data_url] = domain
      ddata[:range] = range_node.text.strip + ' ' + range_node.name.strip
      ddata[:reach_percentage] = cs.xpath('Reach/Percentage').text.strip
      ddata[:pageviews_percentage] = cs.xpath('PageViews/Percentage').text.strip
      ddata[:pageviews_peruser] = cs.xpath('PageViews/PerUser').text.strip

      @data[domain] = ddata
    end
  end

end

Dynamic Method Handling

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