oxm 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +48 -0
- data/CHANGELOG.markdown +3 -0
- data/Gemfile +3 -14
- data/Gemfile.lock +12 -17
- data/LICENSE.txt +1 -1
- data/README.markdown +2 -5
- data/Rakefile +2 -46
- data/lib/oxm.rb +2 -2
- data/lib/oxm/version.rb +3 -0
- data/oxm.gemspec +20 -0
- data/test/test_oxm.rb +16 -10
- metadata +26 -49
data/.gitignore
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
18
|
+
#
|
19
|
+
# * Create a file at ~/.gitignore
|
20
|
+
# * Include files you want ignored
|
21
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
22
|
+
#
|
23
|
+
# After doing this, these files will be ignored in all your git projects,
|
24
|
+
# saving you from having to 'pollute' every project you touch with them
|
25
|
+
#
|
26
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
27
|
+
#
|
28
|
+
# For MacOS:
|
29
|
+
#
|
30
|
+
#.DS_Store
|
31
|
+
|
32
|
+
# For TextMate
|
33
|
+
#*.tmproj
|
34
|
+
#tmtags
|
35
|
+
|
36
|
+
# For emacs:
|
37
|
+
#*~
|
38
|
+
#\#*
|
39
|
+
#.\#*
|
40
|
+
|
41
|
+
# For vim:
|
42
|
+
*.swp
|
43
|
+
|
44
|
+
# For redcar:
|
45
|
+
#.redcar
|
46
|
+
|
47
|
+
# For rubinius:
|
48
|
+
#*.rbc
|
data/CHANGELOG.markdown
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
### 0.2.0 / 2013/05/15
|
2
|
+
* OXM.from_xml now returns an Enumerator when block is not given
|
3
|
+
|
1
4
|
### 0.1.3 / 2011/09/27
|
2
5
|
* OXM can be instantiated. Warning and error messages during the last OXM#from_xml call can be accessed with OXM#warnings and OXM#errors instance methods.
|
3
6
|
|
data/Gemfile
CHANGED
@@ -1,15 +1,4 @@
|
|
1
|
-
source
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
1
|
+
source 'https://rubygems.org'
|
5
2
|
|
6
|
-
#
|
7
|
-
|
8
|
-
group :development do
|
9
|
-
gem "bundler", "~> 1.0.0"
|
10
|
-
gem "jeweler", "~> 1.6.4"
|
11
|
-
gem "rcov", ">= 0"
|
12
|
-
end
|
13
|
-
|
14
|
-
gem "builder", ">= 3.0.0"
|
15
|
-
gem "nokogiri", ">= 1.5.0"
|
3
|
+
# Specify your gem's dependencies in oxm.gemspec
|
4
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
oxm (0.2.0)
|
5
|
+
builder (>= 3.0.0)
|
6
|
+
nokogiri (>= 1.5.0)
|
7
|
+
|
1
8
|
GEM
|
2
|
-
remote:
|
9
|
+
remote: https://rubygems.org/
|
3
10
|
specs:
|
4
|
-
builder (3.0.
|
5
|
-
|
6
|
-
|
7
|
-
bundler (~> 1.0)
|
8
|
-
git (>= 1.2.5)
|
9
|
-
rake
|
10
|
-
nokogiri (1.5.0)
|
11
|
-
nokogiri (1.5.0-java)
|
12
|
-
rake (0.9.2)
|
13
|
-
rcov (0.9.10)
|
14
|
-
rcov (0.9.10-java)
|
11
|
+
builder (3.0.4)
|
12
|
+
nokogiri (1.5.9)
|
13
|
+
nokogiri (1.5.9-java)
|
15
14
|
|
16
15
|
PLATFORMS
|
17
16
|
java
|
18
17
|
ruby
|
19
18
|
|
20
19
|
DEPENDENCIES
|
21
|
-
|
22
|
-
bundler (~> 1.0.0)
|
23
|
-
jeweler (~> 1.6.4)
|
24
|
-
nokogiri (>= 1.5.0)
|
25
|
-
rcov
|
20
|
+
oxm!
|
data/LICENSE.txt
CHANGED
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# oxm
|
2
2
|
|
3
|
-
A tiny, easy-to-use Object-XML-Mapper for Ruby.
|
3
|
+
A tiny, easy-to-use Object-XML-Mapper for Ruby.
|
4
4
|
Internally uses Nokogiri SAX parser which allows handling of large XML documents.
|
5
5
|
|
6
6
|
## Installation
|
@@ -61,11 +61,8 @@ end
|
|
61
61
|
items = OXM.from_xml(xml_data_or_io, 'orders/order/item')
|
62
62
|
```
|
63
63
|
|
64
|
-
## TODO
|
65
|
-
* When block is not given, make from_xml return an Enumerator instead of an Array
|
66
|
-
|
67
64
|
## Contributing to oxm
|
68
|
-
|
65
|
+
|
69
66
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
70
67
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
71
68
|
* Fork the project
|
data/Rakefile
CHANGED
@@ -1,30 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "oxm"
|
18
|
-
gem.homepage = "http://github.com/junegunn/oxm"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{A tiny Object-XML-Mapper}
|
21
|
-
gem.description = %Q{A tiny Object-XML-Mapper using Nokogiri SAX parser}
|
22
|
-
gem.email = "junegunn.c@gmail.com"
|
23
|
-
gem.authors = ["Junegunn Choi"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
27
|
-
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
28
3
|
require 'rake/testtask'
|
29
4
|
Rake::TestTask.new(:test) do |test|
|
30
5
|
test.libs << 'lib' << 'test'
|
@@ -32,22 +7,3 @@ Rake::TestTask.new(:test) do |test|
|
|
32
7
|
test.verbose = true
|
33
8
|
end
|
34
9
|
|
35
|
-
require 'rcov/rcovtask'
|
36
|
-
Rcov::RcovTask.new do |test|
|
37
|
-
test.libs << 'test'
|
38
|
-
test.pattern = 'test/**/test_*.rb'
|
39
|
-
test.verbose = true
|
40
|
-
test.rcov_opts << '--exclude "gems/*"'
|
41
|
-
end
|
42
|
-
|
43
|
-
task :default => :test
|
44
|
-
|
45
|
-
require 'rake/rdoctask'
|
46
|
-
Rake::RDocTask.new do |rdoc|
|
47
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
-
|
49
|
-
rdoc.rdoc_dir = 'rdoc'
|
50
|
-
rdoc.title = "oxm #{version}"
|
51
|
-
rdoc.rdoc_files.include('README*')
|
52
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
-
end
|
data/lib/oxm.rb
CHANGED
@@ -19,10 +19,10 @@ class OXM
|
|
19
19
|
|
20
20
|
# @param [String] loop_element
|
21
21
|
def from_xml loop_element, &block
|
22
|
+
return enum_for(:from_xml, loop_element, &block) unless block_given?
|
22
23
|
@handler = OXM::SaxHandler.new(loop_element, &block)
|
23
|
-
parser = Nokogiri::XML::SAX::Parser.new(@handler)
|
24
|
+
parser = Nokogiri::XML::SAX::Parser.new(@handler, 'UTF-8')
|
24
25
|
parser.parse @xml
|
25
|
-
@handler.outputs unless block_given?
|
26
26
|
end
|
27
27
|
|
28
28
|
# @return [Array] Error messages during the last from_xml call
|
data/lib/oxm/version.rb
ADDED
data/oxm.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/oxm/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Junegunn Choi"]
|
6
|
+
gem.email = ["junegunn.c@gmail.com"]
|
7
|
+
gem.description = %q{An Object-XML-Mapper based on Nokogiri SAX parser}
|
8
|
+
gem.summary = %q{An Object-XML-Mapper based on Nokogiri SAX parser}
|
9
|
+
gem.homepage = "https://github.com/junegunn/oxm"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "oxm"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = OXM::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'builder', '>= 3.0.0'
|
19
|
+
gem.add_runtime_dependency 'nokogiri', '>= 1.5.0'
|
20
|
+
end
|
data/test/test_oxm.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'helper'
|
2
3
|
|
3
4
|
class TestOxm < Test::Unit::TestCase
|
@@ -8,7 +9,7 @@ class TestOxm < Test::Unit::TestCase
|
|
8
9
|
<container attr1="1" attr2="2">
|
9
10
|
<item dept="A">
|
10
11
|
<volume unit="ml"><![CDATA[ 100 ]]></volume>
|
11
|
-
<volume unit="ml"><![CDATA[
|
12
|
+
<volume unit="ml"><![CDATA[백]]></volume>
|
12
13
|
</item>
|
13
14
|
<item dept="B">
|
14
15
|
<volume unit="l">200</volume>
|
@@ -19,14 +20,14 @@ class TestOxm < Test::Unit::TestCase
|
|
19
20
|
|
20
21
|
# Test errors (XML declaration allowed only at the start of the document)
|
21
22
|
oxm = OXM.new str
|
22
|
-
result = oxm.from_xml('container')
|
23
|
+
result = oxm.from_xml('container').to_a
|
23
24
|
assert_equal 0, result.length
|
24
25
|
assert_equal 1, oxm.errors.length
|
25
26
|
assert_equal 0, oxm.warnings.length
|
26
27
|
|
27
28
|
# Test no-errors
|
28
29
|
oxm = OXM.new str.strip
|
29
|
-
result = oxm.from_xml('container')
|
30
|
+
result = oxm.from_xml('container').to_a
|
30
31
|
assert_equal 1, result.length
|
31
32
|
assert_equal 0, oxm.errors.length
|
32
33
|
assert_equal 0, oxm.warnings.length
|
@@ -37,12 +38,12 @@ class TestOxm < Test::Unit::TestCase
|
|
37
38
|
tf.flush
|
38
39
|
|
39
40
|
oxm = OXM.new File.open(tf.path)
|
40
|
-
result = oxm.from_xml('container')
|
41
|
+
result = oxm.from_xml('container').to_a
|
41
42
|
assert_equal 1, result.length
|
42
43
|
assert_equal 0, oxm.errors.length
|
43
44
|
assert_equal 0, oxm.warnings.length
|
44
45
|
|
45
|
-
result = oxm.from_xml('container')
|
46
|
+
result = oxm.from_xml('container').to_a
|
46
47
|
assert_equal 0, result.length
|
47
48
|
assert_equal 2, oxm.errors.length
|
48
49
|
assert_equal 0, oxm.warnings.length
|
@@ -80,7 +81,12 @@ class TestOxm < Test::Unit::TestCase
|
|
80
81
|
|
81
82
|
[lambda { str }, lambda { File.open(tf.path) }].each do |input|
|
82
83
|
result = OXM.from_xml(input.call, 'container')
|
83
|
-
|
84
|
+
if defined?(Enumerable::Enumerator)
|
85
|
+
assert result.is_a?(Enumerable::Enumerator)
|
86
|
+
else
|
87
|
+
assert result.is_a?(Enumerator)
|
88
|
+
end
|
89
|
+
result = result.to_a
|
84
90
|
assert_equal 1, result.length
|
85
91
|
assert_equal "", result.first.to_s
|
86
92
|
assert_equal({'attr1' => '1', 'attr2' => '2'}, result.first.attributes)
|
@@ -101,7 +107,7 @@ class TestOxm < Test::Unit::TestCase
|
|
101
107
|
assert container.compact!.equal?(container) # Object identity
|
102
108
|
assert container.item.is_a?(Array)
|
103
109
|
|
104
|
-
result = OXM.from_xml(input.call, 'container/item')
|
110
|
+
result = OXM.from_xml(input.call, 'container/item').to_a
|
105
111
|
assert_equal 4, result.length
|
106
112
|
|
107
113
|
item = result.last
|
@@ -110,7 +116,7 @@ class TestOxm < Test::Unit::TestCase
|
|
110
116
|
assert_equal '500', item.volume.to_s
|
111
117
|
assert_equal 'L', item.volume['unit']
|
112
118
|
|
113
|
-
result = OXM.from_xml(input.call, 'container/item/volume')
|
119
|
+
result = OXM.from_xml(input.call, 'container/item/volume').to_a
|
114
120
|
assert_equal 8, result.length
|
115
121
|
assert_equal %w[100 200 200 300 300 400 500] + [""], result.map(&:to_s)
|
116
122
|
assert_equal %w[ml ml l l l ml L] + [nil], result.map { |e| e['unit'] }
|
@@ -167,7 +173,7 @@ class TestOxm < Test::Unit::TestCase
|
|
167
173
|
<item>
|
168
174
|
</item>
|
169
175
|
<item>
|
170
|
-
|
176
|
+
|
171
177
|
</item>
|
172
178
|
</container>
|
173
179
|
EOF
|
@@ -211,7 +217,7 @@ class TestOxm < Test::Unit::TestCase
|
|
211
217
|
</container>
|
212
218
|
EOF
|
213
219
|
|
214
|
-
items = OXM.from_xml(str, 'container/item')
|
220
|
+
items = OXM.from_xml(str, 'container/item').to_a
|
215
221
|
assert_equal 6, items.length
|
216
222
|
|
217
223
|
items[0].compact!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oxm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,60 +21,37 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: nokogiri
|
27
|
-
requirement: &2158740520 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
27
|
- - ! '>='
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
-
type: :runtime
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *2158740520
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: bundler
|
38
|
-
requirement: &2158738800 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 1.0.0
|
44
|
-
type: :development
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *2158738800
|
29
|
+
version: 3.0.0
|
47
30
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
49
|
-
requirement:
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
50
33
|
none: false
|
51
34
|
requirements:
|
52
|
-
- -
|
35
|
+
- - ! '>='
|
53
36
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
55
|
-
type: :
|
37
|
+
version: 1.5.0
|
38
|
+
type: :runtime
|
56
39
|
prerelease: false
|
57
|
-
version_requirements:
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
name: rcov
|
60
|
-
requirement: &2158735100 !ruby/object:Gem::Requirement
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
41
|
none: false
|
62
42
|
requirements:
|
63
43
|
- - ! '>='
|
64
44
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
description: A tiny Object-XML-Mapper using Nokogiri SAX parser
|
70
|
-
email: junegunn.c@gmail.com
|
45
|
+
version: 1.5.0
|
46
|
+
description: An Object-XML-Mapper based on Nokogiri SAX parser
|
47
|
+
email:
|
48
|
+
- junegunn.c@gmail.com
|
71
49
|
executables: []
|
72
50
|
extensions: []
|
73
|
-
extra_rdoc_files:
|
74
|
-
- LICENSE.txt
|
75
|
-
- README.markdown
|
51
|
+
extra_rdoc_files: []
|
76
52
|
files:
|
77
53
|
- .document
|
54
|
+
- .gitignore
|
78
55
|
- CHANGELOG.markdown
|
79
56
|
- Gemfile
|
80
57
|
- Gemfile.lock
|
@@ -85,11 +62,12 @@ files:
|
|
85
62
|
- lib/oxm.rb
|
86
63
|
- lib/oxm/object.rb
|
87
64
|
- lib/oxm/sax_handler.rb
|
65
|
+
- lib/oxm/version.rb
|
66
|
+
- oxm.gemspec
|
88
67
|
- test/helper.rb
|
89
68
|
- test/test_oxm.rb
|
90
|
-
homepage:
|
91
|
-
licenses:
|
92
|
-
- MIT
|
69
|
+
homepage: https://github.com/junegunn/oxm
|
70
|
+
licenses: []
|
93
71
|
post_install_message:
|
94
72
|
rdoc_options: []
|
95
73
|
require_paths:
|
@@ -100,9 +78,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
78
|
- - ! '>='
|
101
79
|
- !ruby/object:Gem::Version
|
102
80
|
version: '0'
|
103
|
-
segments:
|
104
|
-
- 0
|
105
|
-
hash: -1465942368572815623
|
106
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
82
|
none: false
|
108
83
|
requirements:
|
@@ -111,8 +86,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
86
|
version: '0'
|
112
87
|
requirements: []
|
113
88
|
rubyforge_project:
|
114
|
-
rubygems_version: 1.8.
|
89
|
+
rubygems_version: 1.8.25
|
115
90
|
signing_key:
|
116
91
|
specification_version: 3
|
117
|
-
summary:
|
118
|
-
test_files:
|
92
|
+
summary: An Object-XML-Mapper based on Nokogiri SAX parser
|
93
|
+
test_files:
|
94
|
+
- test/helper.rb
|
95
|
+
- test/test_oxm.rb
|