saxy 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 923e7d1c218d9e304ee18fb87f6f2a1a9d06d384
4
- data.tar.gz: 79b769b7699aee8503635fdfdc10b09afb9665a2
3
+ metadata.gz: f0e96cc425bd1fe4c375deb9588cdd21a84c3856
4
+ data.tar.gz: 47046544a7e65c47b03c530cfd247a24afa9d6f7
5
5
  SHA512:
6
- metadata.gz: edc331020d4c82df9b1d84656699b1060a6a9ee2324032a4a792208b1a991dadfc23c1668db1f2719c30afe967dd2f57f06bf2eafc61e410808a62bcbef44f8d
7
- data.tar.gz: e140b6138c76e6fa602f4ce4a5a284b0b0213235057ea78da5202871bd85fce1e0df0441010eea5b1aee915c188b8520885a66fa9aa518c595e65a5d61ee502d
6
+ metadata.gz: 25ca49ac3e6c18431e8753ad5c1e6675aace9454b34e9e850ae9238700c037751e39976ccb07b04047b7464f3e15140504d4568b08d05083a781af053197c8c8
7
+ data.tar.gz: 63019da2ae2fdfe0fec2428dda34c7b59a4b6e811f44fb693e39c888fa5d6d77410f052667dae38844157440fe381625679779f6a3ea1c7011336f1a3ca12866
@@ -1,14 +1,6 @@
1
1
  script: "bundle exec rspec ./spec/"
2
+ sudo: false
2
3
  language: ruby
3
4
  rvm:
4
- - 2.0.0
5
- - 1.9.3
6
- - 1.9.2
7
- matrix:
8
- include:
9
- - rvm: 1.8.7
10
- gemfile: gemfiles/1.8
11
- - rvm: ree
12
- gemfile: gemfiles/1.8
13
-
14
-
5
+ - 1.8.7
6
+ - ree
@@ -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
- [![Build Status](https://secure.travis-ci.org/monterail/saxy.png)](http://travis-ci.org/monterail/saxy)
3
+ [![Gem Version](https://badge.fury.io/rb/saxy.svg)](https://badge.fury.io/rb/saxy)
4
+ [![Build Status](https://api.travis-ci.org/monterail/saxy.svg)](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 though it and yields objects along the way.
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|
@@ -11,10 +11,6 @@ module Saxy
11
11
  parser.each
12
12
  end
13
13
  end
14
-
15
- def ruby_18?
16
- @ruby_18 ||= RUBY_VERSION =~ /^1\.8/
17
- end
18
14
  end
19
15
  end
20
16
 
@@ -2,10 +2,8 @@ require 'ostruct'
2
2
 
3
3
  module Saxy
4
4
  class OpenStruct < ::OpenStruct
5
- if Saxy.ruby_18?
6
- define_method :id do
7
- @table[:id]
8
- end
5
+ define_method :id do
6
+ @table[:id]
9
7
  end
10
8
  end
11
9
  end
@@ -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(xml_file, object_tag)
20
- @xml_file, @object_tag = xml_file, object_tag
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
- if blk
67
- @callback = blk
66
+ return to_enum unless blk
68
67
 
69
- parser = Nokogiri::XML::SAX::Parser.new(self)
68
+ @callback = blk
70
69
 
71
- if @xml_file.is_a?(IO)
72
- parser.parse_io(@xml_file)
73
- else
74
- parser.parse_file(@xml_file)
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
- to_enum
75
+ parser.parse_file(@object)
78
76
  end
79
77
  end
80
78
  end
@@ -1,3 +1,3 @@
1
1
  module Saxy
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -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.add_dependency "activesupport"
19
- gem.add_dependency "nokogiri"
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
@@ -0,0 +1,9 @@
1
+ class IOLike
2
+ extend Forwardable
3
+
4
+ def_delegators :@io, :read, :close
5
+
6
+ def initialize(io)
7
+ @io = io
8
+ end
9
+ end
@@ -3,12 +3,8 @@ require 'spec_helper'
3
3
  describe Saxy::OpenStruct do
4
4
  let(:object) { Saxy::OpenStruct.new }
5
5
 
6
- if Saxy.ruby_18?
7
- context "in Ruby 1.8" do
8
- it "should correctly set id attribute" do
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
@@ -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 as xml_file" do
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 as xml_file" do
15
- xml_file = File.new(fixture_file("webstore.xml"))
16
- parser = Saxy::Parser.new(xml_file, "product")
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", :unless => RUBY_1_8 do
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
@@ -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", :unless => RUBY_1_8 do
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
@@ -3,5 +3,4 @@ require 'bundler/setup'
3
3
  require 'saxy'
4
4
 
5
5
  require 'fixtures_helper'
6
-
7
- RUBY_1_8 = (RUBY_VERSION =~ /^1\.8/)
6
+ require File.join(File.dirname(__FILE__), 'fixtures', 'io_like')
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.2.3
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: 2013-10-25 00:00:00.000000000 Z
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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.0.0
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.
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "activesupport", "< 4.0.0"
4
- gem "saxy", :path => "../"
5
- gemspec :path => "../"
6
-