multi_xml-0.5.4/ 0000755 0000041 0000041 00000000000 12177604613 013571 5 ustar www-data www-data multi_xml-0.5.4/CONTRIBUTING.md 0000644 0000041 0000041 00000003625 12177604613 016030 0 ustar www-data www-data ## Contributing
In the spirit of [free software][free-sw] , **everyone** is encouraged to help
improve this project.
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
Here are some ways *you* can contribute:
* by using alpha, beta, and prerelease versions
* by reporting bugs
* by suggesting new features
* by writing or editing documentation
* by writing specifications
* by writing code (**no patch is too small**: fix typos, add comments, clean up
inconsistent whitespace)
* by refactoring code
* by resolving [issues][]
* by reviewing patches
[issues]: https://github.com/sferik/multi_xml/issues
## Submitting an Issue
We use the [GitHub issue tracker][issues] to track bugs and features. Before
submitting a bug report or feature request, check to make sure it hasn't
already been submitted. When submitting a bug report, please include a [Gist][]
that includes a stack trace and any details that may be necessary to reproduce
the bug, including your gem version, Ruby version, and operating system.
Ideally, a bug report should include a pull request with failing specs.
[gist]: https://gist.github.com/
## Submitting a Pull Request
1. [Fork the repository.][fork]
2. [Create a topic branch.][branch]
3. Add specs for your unimplemented feature or bug fix.
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
5. Implement your feature or bug fix.
6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
7. Run `open coverage/index.html`. If your changes are not completely covered
by your tests, return to step 3.
8. Add documentation for your feature or bug fix.
9. Run `bundle exec rake doc:yard`. If your changes are not 100% documented, go
back to step 8.
10. Add, commit, and push your changes.
11. [Submit a pull request.][pr]
[fork]: http://help.github.com/fork-a-repo/
[branch]: http://learn.github.com/p/branching.html
[pr]: http://help.github.com/send-pull-requests/
multi_xml-0.5.4/README.md 0000644 0000041 0000041 00000007163 12177604613 015057 0 ustar www-data www-data # MultiXML
[][gem]
[][travis]
[][gemnasium]
[][codeclimate]
[][coveralls]
[gem]: https://rubygems.org/gems/multi_xml
[travis]: http://travis-ci.org/sferik/multi_xml
[gemnasium]: https://gemnasium.com/sferik/multi_xml
[codeclimate]: https://codeclimate.com/github/sferik/multi_xml
[coveralls]: https://coveralls.io/r/sferik/multi_xml
A generic swappable back-end for XML parsing
## Installation
gem install multi_xml
To ensure the code you're installing hasn't been tampered with, it's
recommended that you verify the signature. To do this, you need to add my
public key as a trusted certificate (you only need to do this once):
gem cert --add <(curl -Ls https://raw.github.com/sferik/multi_xml/master/certs/sferik.pem)
Then, install the gem with the high security trust policy:
gem install multi_xml -P HighSecurity
## Documentation
[http://rdoc.info/gems/multi_xml][documentation]
[documentation]: http://rdoc.info/gems/multi_xml
## Usage Examples
Lots of Ruby libraries utilize XML parsing in some form, and everyone has their
favorite XML library. In order to best support multiple XML parsers and
libraries, `multi_xml` is a general-purpose swappable XML backend library. You
use it like so:
```ruby
require 'multi_xml'
MultiXml.parser = :ox
MultiXml.parser = MultiXml::Parsers::Ox # Same as above
MultiXml.parse('This is the contents') # Parsed using Ox
MultiXml.parser = :libxml
MultiXml.parser = MultiXml::Parsers::Libxml # Same as above
MultiXml.parse('This is the contents') # Parsed using LibXML
MultiXml.parser = :nokogiri
MultiXml.parser = MultiXml::Parsers::Nokogiri # Same as above
MultiXml.parse('This is the contents') # Parsed using Nokogiri
MultiXml.parser = :rexml
MultiXml.parser = MultiXml::Parsers::Rexml # Same as above
MultiXml.parse('This is the contents') # Parsed using REXML
```
The `parser` setter takes either a symbol or a class (to allow for custom XML
parsers) that responds to `.parse` at the class level.
MultiXML tries to have intelligent defaulting. That is, if you have any of the
supported parsers already loaded, it will utilize them before attempting to
load any. When loading, libraries are ordered by speed: first Ox, then LibXML,
then Nokogiri, and finally REXML.
## Supported Ruby Versions
This library aims to support and is [tested against][travis] the following Ruby
implementations:
* Ruby 1.8.7
* Ruby 1.9.2
* Ruby 1.9.3
* Ruby 2.0.0
If something doesn't work on one of these interpreters, it's a bug.
This library may inadvertently work (or seem to work) on other Ruby
implementations, however support will only be provided for the versions listed
above.
If you would like this library to support another Ruby version, you may
volunteer to be a maintainer. Being a maintainer entails making sure all tests
run and pass on that implementation. When something breaks on your
implementation, you will be responsible for providing patches in a timely
fashion. If critical issues for a particular implementation exist at the time
of a major release, support for that Ruby version may be dropped.
## Inspiration
MultiXML was inspired by [MultiJSON][].
[multijson]: https://github.com/intridea/multi_json/
## Copyright
Copyright (c) 2010-2013 Erik Michaels-Ober. See [LICENSE][] for details.
[license]: LICENSE.md
multi_xml-0.5.4/Rakefile 0000644 0000041 0000041 00000000661 12177604613 015241 0 ustar www-data www-data require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :test => :spec
task :default => :spec
namespace :doc do
require 'yard'
YARD::Rake::YardocTask.new do |task|
task.files = ['lib/**/*.rb', '-', 'LICENSE.md']
task.options = [
'--no-private',
'--protected',
'--output-dir', 'doc/yard',
'--markup', 'markdown',
]
end
end
multi_xml-0.5.4/spec/ 0000755 0000041 0000041 00000000000 12177604613 014523 5 ustar www-data www-data multi_xml-0.5.4/spec/speed.rb 0000755 0000041 0000041 00000002512 12177604613 016153 0 ustar www-data www-data #!/usr/bin/env ruby -wW1
$: << '.'
$: << '../lib'
if __FILE__ == $0
while (i = ARGV.index('-I'))
x,path = ARGV.slice!(i, 2)
$: << path
end
end
require 'optparse'
require 'stringio'
require 'multi_xml'
begin
require 'libxml'
rescue Exception => e
end
begin
require 'nokogiri'
rescue Exception => e
end
begin
require 'ox'
rescue Exception => e
end
$verbose = 0
$parsers = []
$iter = 10
opts = OptionParser.new
opts.on("-v", "increase verbosity") { $verbose += 1 }
opts.on("-p", "--parser [String]", String, "parser to test") { |p| $parsers = [p] }
opts.on("-i", "--iterations [Int]", Integer, "iterations") { |i| $iter = i }
opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
files = opts.parse(ARGV)
if $parsers.empty?
$parsers << 'libxml' if defined?(::LibXML)
$parsers << 'nokogiri' if defined?(::Nokogiri)
$parsers << 'ox' if defined?(::Ox)
end
files.each do |filename|
times = { }
xml = File.read(filename)
$parsers.each do |p|
MultiXml.parser = p
start = Time.now
$iter.times do |i|
io = StringIO.new(xml)
MultiXml.parse(io)
end
dt = Time.now - start
times[p] = Time.now - start
end
times.each do |p,t|
puts "%8s took %0.3f seconds to parse %s %d times." % [p, t, filename, $iter]
end
end
multi_xml-0.5.4/spec/multi_xml_spec.rb 0000644 0000041 0000041 00000002353 12177604613 020077 0 ustar www-data www-data require 'helper'
require 'parser_shared_example'
class MockDecoder; end
describe "MultiXml" do
context "Parsers" do
it "picks a default parser" do
expect(MultiXml.parser).to be_kind_of(Module)
expect(MultiXml.parser).to respond_to(:parse)
end
it "defaults to the best available gem" do
pending
expect(MultiXml.parser.name).to eq('MultiXml::Parsers::Rexml')
require 'nokogiri'
expect(MultiXml.parser.name).to eq('MultiXml::Parsers::Nokogiri')
require 'libxml'
expect(MultiXml.parser.name).to eq('MultiXml::Parsers::Libxml')
end
it "is settable via a symbol" do
MultiXml.parser = :nokogiri
expect(MultiXml.parser.name).to eq('MultiXml::Parsers::Nokogiri')
end
it "is settable via a class" do
MultiXml.parser = MockDecoder
expect(MultiXml.parser.name).to eq('MockDecoder')
end
end
[['LibXML', 'libxml'],
['REXML', 'rexml/document'],
['Nokogiri', 'nokogiri'],
['Ox', 'ox']].each do |parser|
begin
require parser.last
context "#{parser.first} parser" do
it_behaves_like "a parser", parser.first
end
rescue LoadError => e
puts "Tests not run for #{parser.first} due to a LoadError"
end
end
end
multi_xml-0.5.4/spec/helper.rb 0000644 0000041 0000041 00000000506 12177604613 016330 0 ustar www-data www-data require 'simplecov'
require 'coveralls'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
SimpleCov.start
require 'multi_xml'
require 'rspec'
RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect
end
end
multi_xml-0.5.4/spec/parser_shared_example.rb 0000644 0000041 0000041 00000053213 12177604613 021411 0 ustar www-data www-data shared_examples_for "a parser" do |parser|
before do
begin
MultiXml.parser = parser
rescue LoadError
pending "Parser #{parser} couldn't be loaded"
end
end
describe ".parse" do
context "a blank string" do
before do
@xml = ''
end
it "returns an empty Hash" do
expect(MultiXml.parse(@xml)).to eq({})
end
end
context "a whitespace string" do
before do
@xml = ' '
end
it "returns an empty Hash" do
expect(MultiXml.parse(@xml)).to eq({})
end
end
context "an invalid XML document" do
before do
@xml = ''
end
it "raises MultiXml::ParseError" do
expect{MultiXml.parse(@xml)}.to raise_error(MultiXml::ParseError)
end
end
context "a valid XML document" do
before do
@xml = ''
end
it "parses correctly" do
expect(MultiXml.parse(@xml)).to eq({'user' => nil})
end
context "with CDATA" do
before do
@xml = ''
end
it "returns the correct CDATA" do
expect(MultiXml.parse(@xml)['user']).to eq("Erik Michaels-Ober")
end
end
context "with content" do
before do
@xml = 'Erik Michaels-Ober'
end
it "returns the correct content" do
expect(MultiXml.parse(@xml)['user']).to eq("Erik Michaels-Ober")
end
end
context "with an attribute" do
before do
@xml = ''
end
it "returns the correct attribute" do
expect(MultiXml.parse(@xml)['user']['name']).to eq("Erik Michaels-Ober")
end
end
context "with multiple attributes" do
before do
@xml = ''
end
it "returns the correct attributes" do
expect(MultiXml.parse(@xml)['user']['name']).to eq("Erik Michaels-Ober")
expect(MultiXml.parse(@xml)['user']['screen_name']).to eq("sferik")
end
end
context "typecast management" do
before do
@xml = %Q{
Settings
Test
}
end
context "with :typecast_xml_value => true" do
before do
@setting = MultiXml.parse(@xml)["global_settings"]["group"]["setting"]
end
it { expect(@setting).to eq "" }
end
context "with :typecast_xml_value => false" do
before do
@setting = MultiXml.parse(@xml, :typecast_xml_value => false)["global_settings"]["group"]["setting"]
end
it { expect(@setting).to eq({"type"=>"string", "description"=>{"__content__"=>"Test"}}) }
end
end
context "with :symbolize_keys => true" do
before do
@xml = 'Erik Michaels-Ober'
end
it "symbolizes keys" do
expect(MultiXml.parse(@xml, :symbolize_keys => true)).to eq({:user => {:name => "Erik Michaels-Ober"}})
end
end
context "when value is true" do
before do
pending
@xml = 'true'
end
it "returns true" do
expect(MultiXml.parse(@xml)['tag']).to be_true
end
end
context "when value is false" do
before do
pending
@xml = 'false'
end
it "returns false" do
expect(MultiXml.parse(@xml)['tag']).to be_false
end
end
context "when key is id" do
before do
pending
@xml = '1'
end
it "returns a Fixnum" do
expect(MultiXml.parse(@xml)['id']).to be_a(Fixnum)
end
it "returns the correct number" do
expect(MultiXml.parse(@xml)['id']).to eq(1)
end
end
context "when key contains _id" do
before do
pending
@xml = '1'
end
it "returns a Fixnum" do
expect(MultiXml.parse(@xml)['tag_id']).to be_a(Fixnum)
end
it "returns the correct number" do
expect(MultiXml.parse(@xml)['tag_id']).to eq(1)
end
end
context "with an attribute type=\"boolean\"" do
%w(true false).each do |boolean|
context "when #{boolean}" do
it "returns #{boolean}" do
xml = "#{boolean}"
expect(MultiXml.parse(xml)['tag']).to instance_eval("be_#{boolean}")
end
end
end
context "when 1" do
before do
@xml = '1'
end
it "returns true" do
expect(MultiXml.parse(@xml)['tag']).to be_true
end
end
context "when 0" do
before do
@xml = '0'
end
it "returns false" do
expect(MultiXml.parse(@xml)['tag']).to be_false
end
end
end
context "with an attribute type=\"integer\"" do
context "with a positive integer" do
before do
@xml = '1'
end
it "returns a Fixnum" do
expect(MultiXml.parse(@xml)['tag']).to be_a(Fixnum)
end
it "returns a positive number" do
expect(MultiXml.parse(@xml)['tag']).to be > 0
end
it "returns the correct number" do
expect(MultiXml.parse(@xml)['tag']).to eq(1)
end
end
context "with a negative integer" do
before do
@xml = '-1'
end
it "returns a Fixnum" do
expect(MultiXml.parse(@xml)['tag']).to be_a(Fixnum)
end
it "returns a negative number" do
expect(MultiXml.parse(@xml)['tag']).to be < 0
end
it "returns the correct number" do
expect(MultiXml.parse(@xml)['tag']).to eq(-1)
end
end
end
context "with an attribute type=\"string\"" do
before do
@xml = ''
end
it "returns a String" do
expect(MultiXml.parse(@xml)['tag']).to be_a(String)
end
it "returns the correct string" do
expect(MultiXml.parse(@xml)['tag']).to eq("")
end
end
context "with an attribute type=\"date\"" do
before do
@xml = '1970-01-01'
end
it "returns a Date" do
expect(MultiXml.parse(@xml)['tag']).to be_a(Date)
end
it "returns the correct date" do
expect(MultiXml.parse(@xml)['tag']).to eq(Date.parse('1970-01-01'))
end
end
context "with an attribute type=\"datetime\"" do
before do
@xml = '1970-01-01 00:00'
end
it "returns a Time" do
expect(MultiXml.parse(@xml)['tag']).to be_a(Time)
end
it "returns the correct time" do
expect(MultiXml.parse(@xml)['tag']).to eq(Time.parse('1970-01-01 00:00'))
end
end
context "with an attribute type=\"dateTime\"" do
before do
@xml = '1970-01-01 00:00'
end
it "returns a Time" do
expect(MultiXml.parse(@xml)['tag']).to be_a(Time)
end
it "returns the correct time" do
expect(MultiXml.parse(@xml)['tag']).to eq(Time.parse('1970-01-01 00:00'))
end
end
context "with an attribute type=\"double\"" do
before do
@xml = '3.14159265358979'
end
it "returns a Float" do
expect(MultiXml.parse(@xml)['tag']).to be_a(Float)
end
it "returns the correct number" do
expect(MultiXml.parse(@xml)['tag']).to eq(3.14159265358979)
end
end
context "with an attribute type=\"decimal\"" do
before do
@xml = '3.14159265358979'
end
it "returns a BigDecimal" do
expect(MultiXml.parse(@xml)['tag']).to be_a(BigDecimal)
end
it "returns the correct number" do
expect(MultiXml.parse(@xml)['tag']).to eq(3.14159265358979)
end
end
context "with an attribute type=\"base64Binary\"" do
before do
@xml = 'aW1hZ2UucG5n'
end
it "returns a String" do
expect(MultiXml.parse(@xml)['tag']).to be_a(String)
end
it "returns the correct string" do
expect(MultiXml.parse(@xml)['tag']).to eq("image.png")
end
end
context "with an attribute type=\"yaml\"" do
before do
@xml = "--- \n1: returns an integer\n:message: Have a nice day\narray: \n- has-dashes: true\n has_underscores: true\n"
end
it "raises MultiXML::DisallowedTypeError by default" do
expect{ MultiXml.parse(@xml)['tag'] }.to raise_error(MultiXml::DisallowedTypeError)
end
it "returns the correctly parsed YAML when the type is allowed" do
expect(MultiXml.parse(@xml, :disallowed_types => [])['tag']).to eq({:message => "Have a nice day", 1 => "returns an integer", "array" => [{"has-dashes" => true, "has_underscores" => true}]})
end
end
context "with an attribute type=\"symbol\"" do
before do
@xml = "my_symbol"
end
it "raises MultiXML::DisallowedTypeError" do
expect{ MultiXml.parse(@xml)['tag'] }.to raise_error(MultiXml::DisallowedTypeError)
end
it "returns the correctly parsed Symbol when the type is allowed" do
expect(MultiXml.parse(@xml, :disallowed_types => [])['tag']).to eq(:my_symbol)
end
end
context "with an attribute type=\"file\"" do
before do
@xml = 'ZGF0YQ=='
end
it "returns a StringIO" do
expect(MultiXml.parse(@xml)['tag']).to be_a(StringIO)
end
it "is decoded correctly" do
expect(MultiXml.parse(@xml)['tag'].string).to eq('data')
end
it "has the correct file name" do
expect(MultiXml.parse(@xml)['tag'].original_filename).to eq('data.txt')
end
it "has the correct content type" do
expect(MultiXml.parse(@xml)['tag'].content_type).to eq('text/plain')
end
context "with missing name and content type" do
before do
@xml = 'ZGF0YQ=='
end
it "returns a StringIO" do
expect(MultiXml.parse(@xml)['tag']).to be_a(StringIO)
end
it "is decoded correctly" do
expect(MultiXml.parse(@xml)['tag'].string).to eq('data')
end
it "has the default file name" do
expect(MultiXml.parse(@xml)['tag'].original_filename).to eq('untitled')
end
it "has the default content type" do
expect(MultiXml.parse(@xml)['tag'].content_type).to eq('application/octet-stream')
end
end
end
context "with an attribute type=\"array\"" do
before do
@xml = 'Erik Michaels-OberWynn Netherland'
end
it "returns an Array" do
expect(MultiXml.parse(@xml)['users']).to be_a(Array)
end
it "returns the correct array" do
expect(MultiXml.parse(@xml)['users']).to eq(["Erik Michaels-Ober", "Wynn Netherland"])
end
end
context "with an attribute type=\"array\" in addition to other attributes" do
before do
@xml = 'Erik Michaels-OberWynn Netherland'
end
it "returns an Array" do
expect(MultiXml.parse(@xml)['users']).to be_a(Array)
end
it "returns the correct array" do
expect(MultiXml.parse(@xml)['users']).to eq(["Erik Michaels-Ober", "Wynn Netherland"])
end
end
context "with an attribute type=\"array\" containing only one item" do
before do
@xml = 'Erik Michaels-Ober'
end
it "returns an Array" do
expect(MultiXml.parse(@xml)['users']).to be_a(Array)
end
it "returns the correct array" do
expect(MultiXml.parse(@xml)['users']).to eq(["Erik Michaels-Ober"])
end
end
%w(integer boolean date datetime file).each do |type|
context "with an empty attribute type=\"#{type}\"" do
before do
@xml = ""
end
it "returns nil" do
expect(MultiXml.parse(@xml)['tag']).to be_nil
end
end
end
%w{yaml symbol}.each do |type|
context "with an empty attribute type=\"#{type}\"" do
before do
@xml = ""
end
it "raises MultiXml::DisallowedTypeError by default" do
expect{ MultiXml.parse(@xml)['tag']}.to raise_error(MultiXml::DisallowedTypeError)
end
it "returns nil when the type is allowed" do
expect(MultiXml.parse(@xml, :disallowed_types => [])['tag']).to be_nil
end
end
end
context "with an empty attribute type=\"array\"" do
before do
@xml = ''
end
it "returns an empty Array" do
expect(MultiXml.parse(@xml)['tag']).to eq([])
end
context "with whitespace" do
before do
@xml = ' '
end
it "returns an empty Array" do
expect(MultiXml.parse(@xml)['tag']).to eq([])
end
end
end
context "with XML entities" do
before do
@xml_entities = {
"<" => "<",
">" => ">",
'"' => """,
"'" => "'",
"&" => "&"
}
end
context "in content" do
it "returns unescaped XML entities" do
@xml_entities.each do |key, value|
xml = "#{value}"
expect(MultiXml.parse(xml)['tag']).to eq(key)
end
end
end
context "in attribute" do
it "returns unescaped XML entities" do
@xml_entities.each do |key, value|
xml = ""
expect(MultiXml.parse(xml)['tag']['attribute']).to eq(key)
end
end
end
end
context "with dasherized tag" do
before do
@xml = ''
end
it "returns undasherize tag" do
expect(MultiXml.parse(@xml).keys).to include('tag_1')
end
end
context "with dasherized attribute" do
before do
@xml = ''
end
it "returns undasherize attribute" do
expect(MultiXml.parse(@xml)['tag'].keys).to include('attribute_1')
end
end
context "with children" do
context "with attributes" do
before do
@xml = ''
end
it "returns the correct attributes" do
expect(MultiXml.parse(@xml)['users']['user']['name']).to eq("Erik Michaels-Ober")
end
end
context "with text" do
before do
@xml = 'Erik Michaels-Ober'
end
it "returns the correct text" do
expect(MultiXml.parse(@xml)['user']['name']).to eq("Erik Michaels-Ober")
end
end
context "with an unrecognized attribute type" do
before do
@xml = 'Erik Michaels-Ober'
end
it "passes through the type" do
expect(MultiXml.parse(@xml)['user']['type']).to eq('admin')
end
end
context "with attribute tags on content nodes" do
context "non 'type' attributes" do
before do
@xml = <<-XML
123
0.123
XML
@parsed_xml = MultiXml.parse(@xml)
end
it "adds the attributes to the value hash" do
expect(@parsed_xml['options']['value'][0]['__content__']).to eq('123')
expect(@parsed_xml['options']['value'][0]['currency']).to eq('USD')
expect(@parsed_xml['options']['value'][1]['__content__']).to eq('0.123')
expect(@parsed_xml['options']['value'][1]['number']).to eq('percent')
end
end
context "unrecognized type attributes" do
before do
@xml = <<-XML
123
0.123
123
XML
@parsed_xml = MultiXml.parse(@xml)
end
it "adds the attributes to the value hash passing through the type" do
expect(@parsed_xml['options']['value'][0]['__content__']).to eq('123')
expect(@parsed_xml['options']['value'][0]['type']).to eq('USD')
expect(@parsed_xml['options']['value'][1]['__content__']).to eq('0.123')
expect(@parsed_xml['options']['value'][1]['type']).to eq('percent')
expect(@parsed_xml['options']['value'][2]['__content__']).to eq('123')
expect(@parsed_xml['options']['value'][2]['currency']).to eq('USD')
end
end
context "mixing attributes and non-attributes content nodes type attributes" do
before do
@xml = <<-XML
123
0.123
123
XML
@parsed_xml = MultiXml.parse(@xml)
end
it "adds the attributes to the value hash passing through the type" do
expect(@parsed_xml['options']['value'][0]['__content__']).to eq('123')
expect(@parsed_xml['options']['value'][0]['type']).to eq('USD')
expect(@parsed_xml['options']['value'][1]['__content__']).to eq('0.123')
expect(@parsed_xml['options']['value'][1]['type']).to eq('percent')
expect(@parsed_xml['options']['value'][2]).to eq('123')
end
end
context "mixing recognized type attribute and non-type attributes on content nodes" do
before do
@xml = <<-XML
123
XML
@parsed_xml = MultiXml.parse(@xml)
end
it "adds the the non-type attribute and remove the recognized type attribute and do the typecast" do
expect(@parsed_xml['options']['value']['__content__']).to eq(123)
expect(@parsed_xml['options']['value']['number']).to eq('USD')
end
end
context "mixing unrecognized type attribute and non-type attributes on content nodes" do
before do
@xml = <<-XML
123
XML
@parsed_xml = MultiXml.parse(@xml)
end
it "adds the the non-type attributes and type attribute to the value hash" do
expect(@parsed_xml['options']['value']['__content__']).to eq('123')
expect(@parsed_xml['options']['value']['number']).to eq('USD')
expect(@parsed_xml['options']['value']['type']).to eq('currency')
end
end
end
context "with newlines and whitespace" do
before do
@xml = <<-XML
Erik Michaels-Ober
XML
end
it "parses correctly" do
expect(MultiXml.parse(@xml)).to eq({"user" => {"name" => "Erik Michaels-Ober"}})
end
end
# Babies having babies
context "with children" do
before do
@xml = ''
end
it "parses correctly" do
expect(MultiXml.parse(@xml)).to eq({"users" => {"user" => {"name" => "Erik Michaels-Ober", "status" => {"text" => "Hello"}}}})
end
end
end
context "with sibling children" do
before do
@xml = 'Erik Michaels-OberWynn Netherland'
end
it "returns an Array" do
expect(MultiXml.parse(@xml)['users']['user']).to be_a(Array)
end
it "parses correctly" do
expect(MultiXml.parse(@xml)).to eq({"users" => {"user" => ["Erik Michaels-Ober", "Wynn Netherland"]}})
end
end
end
end
end
multi_xml-0.5.4/metadata.yml 0000644 0000041 0000041 00000006751 12177604613 016105 0 ustar www-data www-data --- !ruby/object:Gem::Specification
name: multi_xml
version: !ruby/object:Gem::Version
version: 0.5.4
prerelease:
platform: ruby
authors:
- Erik Michaels-Ober
autorequire:
bindir: bin
cert_chain:
- !binary |-
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURMakNDQWhhZ0F3SUJB
Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREE5TVE4d0RRWURWUVFEREFaelpt
VnkKYVdzeEZUQVRCZ29Ka2lhSmsvSXNaQUVaRmdWbmJXRnBiREVUTUJFR0Nn
bVNKb21UOGl4a0FSa1dBMk52YlRBZQpGdzB4TXpBeU1ETXhNREF5TWpkYUZ3
MHhOREF5TURNeE1EQXlNamRhTUQweER6QU5CZ05WQkFNTUJuTm1aWEpwCmF6
RVZNQk1HQ2dtU0pvbVQ4aXhrQVJrV0JXZHRZV2xzTVJNd0VRWUtDWkltaVpQ
eUxHUUJHUllEWTI5dE1JSUIKSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4
QU1JSUJDZ0tDQVFFQWwweDVkeDh1S3hpN1Rrckl1eUJVVEpWQgp2MW85M25V
QjlqL3k0TTk2Z1Yycll3QWNpMUpQQnNlTmQ2RnliempvM1lHdUhsN0VRSHVT
SE5hZjFwMmx4ZXcvCnk2MEpYSUpCQmdQY0RLL0tDUDROVUhvZm0wamZvWUQr
SDV1TkpmSENOcTcvWnNUeE90RTNSYTkyczBCQ01UcG0Kd0JNTWxXUjVNdGRF
aElZdUJPNFhobmVqWWdIMEwvN0JMMmx5bW50Vm5zci9hZ2RRb29qUUNOMUlR
bXNSSnZyUgpkdVpSTzN0WnZvSW8xcEJjNEpFZWhEdXFDZXlCZ1BMT3FNb0t0
UWxvbGQxVFFzMWtXVUJLN0tXTUZFaEtDL0tnCnp5ektSSFFvOXlEWXdPdllu
Z29CTFkrVC9sd0NUNGR5c3NkaHpSYmZueEFoYUt1NFNBc3NJd2FDMDF5Vm93
SUQKQVFBQm96a3dOekFKQmdOVkhSTUVBakFBTUIwR0ExVWREZ1FXQkJTMHJ1
RGZSYWs1Y2kxT3BETlgvWmRERWtJcwppVEFMQmdOVkhROEVCQU1DQkxBd0RR
WUpLb1pJaHZjTkFRRUZCUUFEZ2dFQkFISFNNcy9NUDBzT2FMa0V2NEpvCnp2
a20zcW41QTZ0MHZhSHg3NzRjbWVqeU1VKzV3eVN4UmV6c3BMN1VMaDlOZXVL
Mk9oVStPZTNUcHFyQWc1VEsKUjhHUUlMblZ1MkZlbUdBNnNBa1BEbGNQdGdB
NmllSTE5UFpPRjZIVkxtYy9JRC9kUC9OZ1pXV3pFZXFRS21jSwoyK0hNK1NF
RURoWmtTY1lla3c0Wk9lMTY0WnRaRzgxNm9BdjV4MHBHaXRTSWt1bVVwN1Y4
aUVaLzZlaHI3WTllClhPZzRlZXVuNUwvSmptakFSb1cya05kdmtSRDNjMkVl
U0xxV3ZRUnNCbHlwSGZoczZKSnVMbHlaUEdoVTNSL3YKU2YzbFZLcEJDV2dS
cEdUdnk0NVhWcEIrNTl5MzNQSm1FdVExUFRFT1l2UXlhbzlVS01BQWFBTi83
cVdRdGpsMApobHc9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
date: 2013-06-04 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: bundler
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
description: Provides swappable XML backends utilizing LibXML, Nokogiri, Ox, or REXML.
email: sferik@gmail.com
executables: []
extensions: []
extra_rdoc_files: []
files:
- .yardopts
- CHANGELOG.md
- CONTRIBUTING.md
- LICENSE.md
- README.md
- Rakefile
- multi_xml.gemspec
- lib/multi_xml/parsers/libxml.rb
- lib/multi_xml/parsers/libxml2_parser.rb
- lib/multi_xml/parsers/nokogiri.rb
- lib/multi_xml/parsers/ox.rb
- lib/multi_xml/parsers/rexml.rb
- lib/multi_xml/version.rb
- lib/multi_xml.rb
- spec/helper.rb
- spec/multi_xml_spec.rb
- spec/parser_shared_example.rb
- spec/speed.rb
homepage: https://github.com/sferik/multi_xml
licenses:
- MIT
post_install_message:
rdoc_options: []
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: 1.3.5
requirements: []
rubyforge_project:
rubygems_version: 1.8.23
signing_key:
specification_version: 3
summary: A generic swappable back-end for XML parsing
test_files:
- spec/helper.rb
- spec/multi_xml_spec.rb
- spec/parser_shared_example.rb
- spec/speed.rb
has_rdoc:
multi_xml-0.5.4/metadata.gz.sig 0000644 0000041 0000041 00000000400 12177604613 016466 0 ustar www-data www-data FbnK*n-Wc娹E)ۉp5UITﱩ,˰psDCʊZl;1moدb~