module Fletcher::Nokogiri::XML::NodeSet

Public Instance Methods

attribute_array() click to toggle source

convert nodeset models to an array of hashes

@doc.xpath("//img")).attribute_array # => [{:element => "img", :src => ".../someimage.png"}]
# File lib/fletcher/nokogiri.rb, line 29
def attribute_array
  a = Array.new
  each do |node|
    temp_hash = Hash.new 
    case node 
    when ::Nokogiri::XML::Element
      temp_hash[:element] = node.name
      node.attributes.each do |key, value|
        case value
        when ::Nokogiri::XML::Attr
          temp_hash[key.to_sym] = value.value.sanitize
        end 
      end
    end 
    a << temp_hash            
  end
  return a          
end
first_string() click to toggle source

get string from first nodeset model

# File lib/fletcher/nokogiri.rb, line 15
def first_string
  node = first
  case node
  # xml/html element?
  when ::Nokogiri::XML::Element 
    return node.content.sanitize
  # xml/html attribute?
  when ::Nokogiri::XML::Attr
    return node.value.sanitize
  end
end