Parent

Class/Module Index [+]

Quicksearch

Amazon::Element

Internal wrapper class to provide convenient method to access Nokogiri element value.

Public Class Methods

get(element, path='.') click to toggle source

Return the text value of an element.

# File lib/amazon/ecs.rb, line 288
def get(element, path='.')
  return unless element
  result = element.at_xpath(path)
  result = result.inner_html if result
  result
end
get_array(element, path='.') click to toggle source

Return an array of values based on the given path.

# File lib/amazon/ecs.rb, line 302
def get_array(element, path='.')
  return unless element

  result = element/path
  if (result.is_a? Nokogiri::XML::NodeSet) || (result.is_a? Array)
    result.collect { |item| self.get(item) }
  else
    [self.get(result)]
  end
end
get_hash(element, path='.') click to toggle source

Return child element text values of the given path.

# File lib/amazon/ecs.rb, line 314
def get_hash(element, 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
get_unescaped(element, path='.') click to toggle source

Return an unescaped text value of an element.

# File lib/amazon/ecs.rb, line 296
def get_unescaped(element, path='.')
  result = self.get(element, path)
  CGI::unescapeHTML(result) if result
end
new(element) click to toggle source

Pass Nokogiri::XML::Element object

# File lib/amazon/ecs.rb, line 330
def initialize(element)
  @element = element
end

Public Instance Methods

/(path) click to toggle source

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

# File lib/amazon/ecs.rb, line 340
def /(path)
  elements = @element/path
  return nil if elements.size == 0
  elements
end
attributes() click to toggle source
# File lib/amazon/ecs.rb, line 379
def attributes
  return unless self.elem
  self.elem.attributes
end
elem() click to toggle source

Returns Nokogiri::XML::Element object

# File lib/amazon/ecs.rb, line 335
def elem
  @element
end
get(path='.') click to toggle source

Get the text value of the given path, leave empty to retrieve current element value.

# File lib/amazon/ecs.rb, line 360
def get(path='.')
  Element.get(@element, path)
end
get_array(path='.') click to toggle source

Get the array values of the given path.

# File lib/amazon/ecs.rb, line 370
def get_array(path='.')
  Element.get_array(@element, path)
end
get_element(path) click to toggle source

Similar with search_and_convert but always return first element if more than one elements found

# File lib/amazon/ecs.rb, line 354
def get_element(path)
  elements = get_elements(path)
  elements[0] if elements
end
get_elements(path) click to toggle source

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

# File lib/amazon/ecs.rb, line 347
def get_elements(path)
  elements = self./(path)
  return unless elements
  elements = elements.map{|element| Element.new(element)}
end
get_hash(path='.') click to toggle source

Get the children element text values in hash format with the element names as the hash keys.

# File lib/amazon/ecs.rb, line 375
def get_hash(path='.')
  Element.get_hash(@element, path)
end
get_unescaped(path='.') click to toggle source

Get the unescaped HTML text of the given path.

# File lib/amazon/ecs.rb, line 365
def get_unescaped(path='.')
  Element.get_unescaped(@element, path)
end
to_s() click to toggle source
# File lib/amazon/ecs.rb, line 384
def to_s
  elem.to_s if elem
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.