Sha256: 0cc7a34371de9d4a75bfc16f86def8734fa3267bffbb3e35e8dcbe2fbbde5d57
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
module Dozuki module XML class Node attr_accessor :nokogiri_node def initialize(nokogiri_node) self.nokogiri_node = nokogiri_node end def method_missing(method, *args, &blk) nokogiri_node.send(method, *args, &blk) end def respond_to?(method) nokogiri_node.respond_to?(method) ? true : super end def each(xpath, &blk) collection = NodeCollection.new(nokogiri_node.xpath(xpath)) block_given? ? collection.as_node(&blk) : collection end def string(xpath) Parser.to_string(get_first_node(xpath)) end def int(xpath) Parser.to_int(get_first_node(xpath)) end def float(xpath) Parser.to_float(get_first_node(xpath)) end def get(xpath) node = Node.new(get_first_node(xpath)) yield node if block_given? node end def exists?(xpath) !nokogiri_node.xpath(xpath).empty? end private def get_first_node(xpath) node = nokogiri_node.xpath(xpath) raise NotFound.new("Node not found", :xpath => xpath, :node => nokogiri_node) if node.empty? node.first end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dozuki-0.0.1 | lib/dozuki/xml/node.rb |