saxy 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -11
- data/LICENSE.txt +20 -0
- data/README.md +20 -5
- data/lib/saxy.rb +0 -4
- data/lib/saxy/ostruct.rb +2 -4
- data/lib/saxy/parser.rb +9 -11
- data/lib/saxy/version.rb +1 -1
- data/saxy.gemspec +5 -2
- data/spec/fixtures/io_like.rb +9 -0
- data/spec/saxy/ostruct_spec.rb +3 -7
- data/spec/saxy/parser_spec.rb +11 -9
- data/spec/saxy_spec.rb +2 -6
- data/spec/spec_helper.rb +1 -2
- metadata +36 -22
- data/LICENSE +0 -22
- data/gemfiles/gemfile-1.8 +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0e96cc425bd1fe4c375deb9588cdd21a84c3856
|
4
|
+
data.tar.gz: 47046544a7e65c47b03c530cfd247a24afa9d6f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25ca49ac3e6c18431e8753ad5c1e6675aace9454b34e9e850ae9238700c037751e39976ccb07b04047b7464f3e15140504d4568b08d05083a781af053197c8c8
|
7
|
+
data.tar.gz: 63019da2ae2fdfe0fec2428dda34c7b59a4b6e811f44fb693e39c888fa5d6d77410f052667dae38844157440fe381625679779f6a3ea1c7011336f1a3ca12866
|
data/.travis.yml
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2012-2014 Monterail.com LLC
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
# Saxy
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/saxy)
|
4
|
+
[](http://travis-ci.org/monterail/saxy)
|
4
5
|
|
5
6
|
Memory-efficient XML parser. Finds object definitions in XML and translates them into Ruby objects.
|
6
7
|
|
7
|
-
It uses SAX parser under the hood, which means that it doesn't load the whole XML file into memory. It goes once
|
8
|
+
It uses SAX parser under the hood, which means that it doesn't load the whole XML file into memory. It goes once through it and yields objects along the way.
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
12
|
+
This version supports only ruby 1.8, it is not maintained anymore. See master branch if you're looking for support of different ruby versions.
|
13
|
+
|
11
14
|
Add this line to your application's Gemfile:
|
12
15
|
|
13
|
-
gem 'saxy'
|
16
|
+
gem 'saxy', '~> 0.3.0'
|
14
17
|
|
15
18
|
And then execute:
|
16
19
|
|
@@ -18,7 +21,7 @@ And then execute:
|
|
18
21
|
|
19
22
|
Or install it yourself as:
|
20
23
|
|
21
|
-
$ gem install saxy
|
24
|
+
$ gem install saxy --version '~> 0.3.0'
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
@@ -43,11 +46,13 @@ Assume the XML file:
|
|
43
46
|
</products>
|
44
47
|
</webstore>
|
45
48
|
|
46
|
-
You instantiate the parser by passing path to XML file and object-identyfing tag name as its arguments.
|
49
|
+
You instantiate the parser by passing path to XML file or an IO-like object and object-identyfing tag name as its arguments.
|
47
50
|
|
48
51
|
The following will parse the XML, find product definitions (inside `<product>` and `</product>` tags), build `OpenStruct`s and yield them inside the block.
|
49
52
|
Tag attributes become object attributes and attributes' name are underscored.
|
50
53
|
|
54
|
+
Usage with a file path:
|
55
|
+
|
51
56
|
Saxy.parse("filename.xml", "product").each do |product|
|
52
57
|
puts product.name
|
53
58
|
puts product.images.thumb_size.contents
|
@@ -62,6 +67,16 @@ Tag attributes become object attributes and attributes' name are underscored.
|
|
62
67
|
http://amazon.com/kindle_touch_thumb.jpg
|
63
68
|
120x90
|
64
69
|
|
70
|
+
Usage with an IO-like object `ARGF`:
|
71
|
+
|
72
|
+
# > cat filename.xml | ruby this_script.rb
|
73
|
+
Saxy.parse(ARGF, "product").each do |product|
|
74
|
+
puts product.name
|
75
|
+
end
|
76
|
+
|
77
|
+
# =>
|
78
|
+
Kindle - The world's best-selling e-reader.
|
79
|
+
|
65
80
|
Saxy supports Enumerable, so you can use its goodies to your comfort without building intermediate arrays:
|
66
81
|
|
67
82
|
Saxy.parse("filename.xml", "product").map do |object|
|
data/lib/saxy.rb
CHANGED
data/lib/saxy/ostruct.rb
CHANGED
data/lib/saxy/parser.rb
CHANGED
@@ -16,8 +16,8 @@ module Saxy
|
|
16
16
|
# Will yield objects inside the callback after they're built
|
17
17
|
attr_reader :callback
|
18
18
|
|
19
|
-
def initialize(
|
20
|
-
@
|
19
|
+
def initialize(object, object_tag)
|
20
|
+
@object, @object_tag = object, object_tag
|
21
21
|
@tags, @elements = [], []
|
22
22
|
end
|
23
23
|
|
@@ -63,18 +63,16 @@ module Saxy
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def each(&blk)
|
66
|
-
|
67
|
-
@callback = blk
|
66
|
+
return to_enum unless blk
|
68
67
|
|
69
|
-
|
68
|
+
@callback = blk
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
70
|
+
parser = Nokogiri::XML::SAX::Parser.new(self)
|
71
|
+
|
72
|
+
if @object.respond_to?(:read) && @object.respond_to?(:close)
|
73
|
+
parser.parse_io(@object)
|
76
74
|
else
|
77
|
-
|
75
|
+
parser.parse_file(@object)
|
78
76
|
end
|
79
77
|
end
|
80
78
|
end
|
data/lib/saxy/version.rb
CHANGED
data/saxy.gemspec
CHANGED
@@ -15,7 +15,10 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Saxy::VERSION
|
17
17
|
|
18
|
-
gem.
|
19
|
-
|
18
|
+
gem.required_ruby_version = "< 1.9"
|
19
|
+
|
20
|
+
gem.add_dependency "activesupport", "< 4.0.0"
|
21
|
+
gem.add_dependency "i18n", "< 0.7.0"
|
22
|
+
gem.add_dependency "nokogiri", "< 1.6.0"
|
20
23
|
gem.add_development_dependency "rspec"
|
21
24
|
end
|
data/spec/saxy/ostruct_spec.rb
CHANGED
@@ -3,12 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe Saxy::OpenStruct do
|
4
4
|
let(:object) { Saxy::OpenStruct.new }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
object.id = 1
|
10
|
-
object.id.should == 1
|
11
|
-
end
|
12
|
-
end
|
6
|
+
it "should correctly set id attribute" do
|
7
|
+
object.id = 1
|
8
|
+
object.id.should == 1
|
13
9
|
end
|
14
10
|
end
|
data/spec/saxy/parser_spec.rb
CHANGED
@@ -4,16 +4,22 @@ describe Saxy::Parser do
|
|
4
4
|
include FixturesHelper
|
5
5
|
|
6
6
|
let(:parser) { Saxy::Parser.new(fixture_file("webstore.xml"), "product") }
|
7
|
+
let(:file_io) { File.new(fixture_file("webstore.xml")) }
|
8
|
+
let(:io_like) { IOLike.new(file_io) }
|
7
9
|
|
8
|
-
it "should accept string filename
|
10
|
+
it "should accept string filename for parsing" do
|
9
11
|
xml_file = fixture_file("webstore.xml")
|
10
12
|
parser = Saxy::Parser.new(xml_file, "product")
|
11
13
|
parser.each.to_a.size.should == 2
|
12
14
|
end
|
13
15
|
|
14
|
-
it "should accept IO
|
15
|
-
|
16
|
-
parser
|
16
|
+
it "should accept IO for parsing" do
|
17
|
+
parser = Saxy::Parser.new(file_io, "product")
|
18
|
+
parser.each.to_a.size.should == 2
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should accept an IO-like for parsing" do
|
22
|
+
parser = Saxy::Parser.new(io_like, "product")
|
17
23
|
parser.each.to_a.size.should == 2
|
18
24
|
end
|
19
25
|
|
@@ -149,11 +155,7 @@ describe Saxy::Parser do
|
|
149
155
|
lambda { parser.error("Error message.") }.should raise_error(Saxy::ParsingError, "Error message.")
|
150
156
|
end
|
151
157
|
|
152
|
-
it "should return Enumerator when calling #each without a block"
|
153
|
-
parser.each.should be_instance_of Enumerator
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should return Enumerator when calling #each without a block", :if => RUBY_1_8 do
|
158
|
+
it "should return Enumerator when calling #each without a block" do
|
157
159
|
parser.each.should be_instance_of Enumerable::Enumerator
|
158
160
|
end
|
159
161
|
end
|
data/spec/saxy_spec.rb
CHANGED
@@ -31,11 +31,7 @@ describe Saxy do
|
|
31
31
|
webstore.products.product.size.should == 2
|
32
32
|
end
|
33
33
|
|
34
|
-
it "should return Enumerator when calling #parse without a block"
|
35
|
-
Saxy.parse(fixture_file("webstore.xml"), "product").each.should be_instance_of Enumerator
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should return Enumerator when calling #parse without a block", :if => RUBY_1_8 do
|
34
|
+
it "should return Enumerator when calling #parse without a block" do
|
39
35
|
Saxy.parse(fixture_file("webstore.xml"), "product").each.should be_instance_of Enumerable::Enumerator
|
40
36
|
end
|
41
|
-
end
|
37
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michał Szajbe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "<"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "<"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: i18n
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "<"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.7.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: nokogiri
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- -
|
45
|
+
- - "<"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 1.6.0
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - "<"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 1.6.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- -
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
61
|
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- -
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
description: Saxy finds object definitions in XML files and translates them into Ruby
|
@@ -62,14 +76,13 @@ executables: []
|
|
62
76
|
extensions: []
|
63
77
|
extra_rdoc_files: []
|
64
78
|
files:
|
65
|
-
- .gitignore
|
66
|
-
- .rspec
|
67
|
-
- .travis.yml
|
79
|
+
- ".gitignore"
|
80
|
+
- ".rspec"
|
81
|
+
- ".travis.yml"
|
68
82
|
- Gemfile
|
69
|
-
- LICENSE
|
83
|
+
- LICENSE.txt
|
70
84
|
- README.md
|
71
85
|
- Rakefile
|
72
|
-
- gemfiles/gemfile-1.8
|
73
86
|
- lib/saxy.rb
|
74
87
|
- lib/saxy/element.rb
|
75
88
|
- lib/saxy/ostruct.rb
|
@@ -77,6 +90,7 @@ files:
|
|
77
90
|
- lib/saxy/parsing_error.rb
|
78
91
|
- lib/saxy/version.rb
|
79
92
|
- saxy.gemspec
|
93
|
+
- spec/fixtures/io_like.rb
|
80
94
|
- spec/fixtures/webstore.xml
|
81
95
|
- spec/fixtures_helper.rb
|
82
96
|
- spec/saxy/element_spec.rb
|
@@ -93,22 +107,23 @@ require_paths:
|
|
93
107
|
- lib
|
94
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
95
109
|
requirements:
|
96
|
-
- -
|
110
|
+
- - "<"
|
97
111
|
- !ruby/object:Gem::Version
|
98
|
-
version: '
|
112
|
+
version: '1.9'
|
99
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
|
-
- -
|
115
|
+
- - ">="
|
102
116
|
- !ruby/object:Gem::Version
|
103
117
|
version: '0'
|
104
118
|
requirements: []
|
105
119
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.4.8
|
107
121
|
signing_key:
|
108
122
|
specification_version: 4
|
109
123
|
summary: Memory-efficient XML parser. Finds object definitions and translates them
|
110
124
|
into Ruby objects.
|
111
125
|
test_files:
|
126
|
+
- spec/fixtures/io_like.rb
|
112
127
|
- spec/fixtures/webstore.xml
|
113
128
|
- spec/fixtures_helper.rb
|
114
129
|
- spec/saxy/element_spec.rb
|
@@ -116,4 +131,3 @@ test_files:
|
|
116
131
|
- spec/saxy/parser_spec.rb
|
117
132
|
- spec/saxy_spec.rb
|
118
133
|
- spec/spec_helper.rb
|
119
|
-
has_rdoc:
|
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Michał Szajbe
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|