Class: VastApi::Attributes::Entry

Inherits:
Hash
  • Object
show all
Defined in:
lib/vast_api/attributes/entry.rb

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Entry

Returns a new instance of Entry.



5
6
7
8
9
10
11
# File 'lib/vast_api/attributes/entry.rb', line 5

def initialize(doc)
  @attributes = {}
  @doc = doc
  @doc.xpath("v:attribute/v:value").each do |value|
    self[value["id"]] = { :name => value.content, :count => value["count"] }
  end
end

Instance Method Details

#attribute(var_name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/vast_api/attributes/entry.rb', line 13

def attribute(var_name)
  @attributes[var_name] ||=
    if %W{author updated}.index(var_name)
      self.send(var_name)
    elsif %W{ title id content }.index(var_name)
      get_var('xmlns:'+var_name)
    else
      get_var("v:#{var_name}")
    end
end

#authorObject



24
25
26
# File 'lib/vast_api/attributes/entry.rb', line 24

def author
  @attributes['author'] ||= get_children(@doc.at_xpath('xmlns:author'))
end

#updatedObject



28
29
30
# File 'lib/vast_api/attributes/entry.rb', line 28

def updated
  @attributes["updated"] ||= DateTime.strptime(@doc.at_xpath('xmlns:updated').content)
end