lib/happymapper.rb in jnunemaker-happymapper-0.2.1 vs lib/happymapper.rb in jnunemaker-happymapper-0.2.2
- old
+ new
@@ -2,16 +2,13 @@
$:.unshift(dir) unless $:.include?(dir) || $:.include?(File.expand_path(dir))
require 'date'
require 'time'
require 'rubygems'
-
gem 'libxml-ruby', '= 0.9.8'
require 'xml'
-require 'libxml_ext/libxml_helper'
-
class Boolean; end
module HappyMapper
DEFAULT_NS = "happymapper"
@@ -63,14 +60,12 @@
def tag(new_tag_name)
@tag_name = new_tag_name.to_s
end
- def get_tag_name
- @tag_name ||= begin
- to_s.split('::')[-1].downcase
- end
+ def tag_name
+ @tag_name ||= to_s.split('::')[-1].downcase
end
def parse(xml, options = {})
# locally scoped copy of namespace for this parse run
namespace = @namespace
@@ -79,14 +74,14 @@
node = xml
else
if xml.is_a?(XML::Document)
node = xml.root
else
- node = xml.to_libxml_doc.root
+ node = XML::Parser.string(xml).parse.root
end
- root = node.name == get_tag_name
+ root = node.name == tag_name
end
# This is the entry point into the parsing pipeline, so the default
# namespace prefix registered here will propagate down
namespaces = node.namespaces
@@ -95,11 +90,11 @@
namespace ||= DEFAULT_NS
end
xpath = root ? '/' : './/'
xpath += "#{namespace}:" if namespace
- xpath += get_tag_name
+ xpath += tag_name
# puts "parse: #{xpath}"
nodes = node.find(xpath)
collection = nodes.collect do |n|
obj = new
@@ -117,10 +112,9 @@
obj
end
# per http://libxml.rubyforge.org/rdoc/classes/LibXML/XML/Document.html#M000354
nodes = nil
- GC.start
if options[:single] || root
collection.first
else
collection