Class: VastApi::Attributes::Entry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vast, doc) ⇒ Entry

Returns a new instance of Entry.



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

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

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



4
5
6
# File 'lib/vast_api/attributes/entry.rb', line 4

def doc
  @doc
end

#vastObject (readonly)

Returns the value of attribute vast.



4
5
6
# File 'lib/vast_api/attributes/entry.rb', line 4

def vast
  @vast
end

Instance Method Details

#attribute(var_name) ⇒ Object



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

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



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

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

#updatedObject



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

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