Class: Alexa::UrlInfo::ContentData

Inherits:
Object
  • Object
show all
Includes:
Container
Defined in:
lib/alexa/url_info/content_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Container

included, #keys, #method_missing, #to_mongo

Constructor Details

#initialize(xml_node = nil) ⇒ ContentData

Returns a new instance of ContentData.



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
# File 'lib/alexa/url_info/content_data.rb', line 8

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

  if !xml_node.nil?
    @data[:data_url]         = xml_node.xpath('DataUrl').text.strip
    @data[:title]            = xml_node.xpath('SiteData/Title').text.strip
    @data[:description]      = xml_node.xpath('SiteData/Description').text.strip
    @data[:online_since]     = xml_node.xpath('SiteData/OnlineSince').text.strip
    @data[:median_load_time] = xml_node.xpath('Speed/MedianLoadTime').text.strip
    @data[:load_percentile]  = xml_node.xpath('Speed/Percentile').text.strip
    @data[:adult_content]    = xml_node.xpath('AdultContent').text.strip
    @data[:language]         = xml_node.xpath('Language/Locale').text.strip
    @data[:links_in_count]   = xml_node.xpath('LinksInCount').text.strip

    @data[:keywords]         = []
    xml_node.xpath('Keywords/Keyword').each do |kw|
      @data[:keywords] << kw.text.strip
    end

    @data[:owned_domains]    = []
    xml_node.xpath('OwnedDomains/OwnedDomain').each do |d|
      @data[:owned_domains] << {
        :domain => d.xpath('Domain').text.strip,
        :title => d.xpath('Title').text.strip
      }
    end
  end

end

Dynamic Method Handling

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

Instance Attribute Details

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/alexa/url_info/content_data.rb', line 6

def data
  @data
end