Class: ApiBucket::Base::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/api_bucket/base/element.rb

Instance Method Summary collapse

Constructor Details

#initialize(e) ⇒ Element

Returns a new instance of Element.



3
4
5
# File 'lib/api_bucket/base/element.rb', line 3

def initialize(e)
  @element = e
end

Instance Method Details

#/(path) ⇒ Object

Returns a Nokogiri::XML::NodeSet of elements matching the given path. Example: element/“author”.



22
23
24
25
26
# File 'lib/api_bucket/base/element.rb', line 22

def /(elements, path)
  items = self./(elements, path)
  return nil if items.size = 0
  items
end

#get(path) ⇒ Object



7
8
9
10
11
12
# File 'lib/api_bucket/base/element.rb', line 7

def get(path)
  return nil unless @element
  result = @element.at_xpath(path)
  result = result.inner_html if result
  result
end

#get_element(path) ⇒ Object



35
36
37
38
# File 'lib/api_bucket/base/element.rb', line 35

def get_element(path)
  elements = self.get_elements(path)
  elements[0] if elements
end

#get_elements(path) ⇒ Object

Return an array of Amazon::Element matching the given path



29
30
31
32
33
# File 'lib/api_bucket/base/element.rb', line 29

def get_elements(path)
  elements = self./(path)
  return nil unless elements
  elements = elements.map{|element| Element.new(element)}
end

#hash(path = '.') ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/api_bucket/base/element.rb', line 40

def hash(path='.')
  return unless @element

  result = @element.at_xpath(path)
  if result
    hash = {}
    result = result.children
    result.each do |item|
      hash[item.name] = item.inner_html
    end
    hash
  end
end