saxy 0.6.1 → 0.7.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: 071f31e0e4239d7aa2206cddd8d0bbab99982896
4
- data.tar.gz: 9314c5c857ffa12cd30ba32f473a34c01bbfdaca
3
+ metadata.gz: 145b19ea70344eb97cb37dab58b172d07766a654
4
+ data.tar.gz: 9b0a3482befc1f5270f8bfe5665a68b4cc0a87f4
5
5
  SHA512:
6
- metadata.gz: db0123c050ea39667f55e1e2569d5bdd8649a94a3650ec1d73f8c317b42d4c17270e40796a0c58a50fbbaf4be43468941d85473a7164390166db7ee4df96acf8
7
- data.tar.gz: 5fb5c951cf06dff3b7b3385b8ac19a59887a91e8b70f790c4d8e698964551327328900508c7d8a1547bd27aabdcaca7304b2ec823c9d59afd408ba591f97eed4
6
+ metadata.gz: 229a5ceede847656383a9b86a8521d17030c97329233cc36a0a32f6beceb2efcacff06a9e2d030a05c81014f41b9dc3f7c31f83b5cbce933827136149e48bab8
7
+ data.tar.gz: dd980f2f3fc39731e19776316bde8f16abb8f28be32d7f036cfca65db6867fa7dd1d7362360a96e3759b2f389a6e48e6aa3ab88df568ebfb3334174e9492af6c
@@ -2,6 +2,8 @@ script: "bundle exec rspec ./spec/"
2
2
  sudo: false
3
3
  language: ruby
4
4
  rvm:
5
+ - 2.4
6
+ - 2.3
5
7
  - 2.2
6
8
  - 2.1
7
9
  - 2.0.0
@@ -1,5 +1,9 @@
1
1
  # Saxy Changelog
2
2
 
3
+ ## 0.7.0
4
+
5
+ * [BREAKING] Yielded hashes now have strings as keys instead of symbols (performance and security fix).
6
+
3
7
  ## 0.6.1
4
8
 
5
9
  * Fixed passing options from `Saxy.parse` to parser's initializer
data/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/saxy.svg)](https://badge.fury.io/rb/saxy)
4
4
  [![Build Status](https://api.travis-ci.org/humante/saxy.svg)](http://travis-ci.org/humante/saxy)
5
5
 
6
- Memory-efficient XML parser. Finds object definitions in XML and translates them into Ruby objects.
6
+ Memory-efficient XML parser. Finds object definitions in XML and translates them into Ruby hashes.
7
7
 
8
- It uses SAX parser (provided by Nokogiri gem) 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
+ It uses SAX parser (provided by Nokogiri gem) under the hood, which means that it doesn't load the whole XML file into memory. It goes once through it and yields hashes along the way.
9
9
 
10
10
  In result the memory footprint of the parser remains small and more or less constant irrespective of the size of the XML file, be it few KB or hundreds of GB.
11
11
 
@@ -96,9 +96,9 @@ Usage with a file path:
96
96
 
97
97
  ````ruby
98
98
  Saxy.parse("filename.xml", "product").each do |product|
99
- puts product[:name]
100
- puts product[:images][:thumb_size][:contents]
101
- puts "#{product[:images][:thumb_size][:width]}x#{product[:images][:thumb_size][:height]}"
99
+ puts product["name"]
100
+ puts product["images"]["thumb_size"]["contents"]
101
+ puts "#{product["images"]["thumb_size"]["width"]}x#{product["images"]["thumb_size"]["height"]}"
102
102
  end
103
103
 
104
104
  # =>
@@ -115,7 +115,7 @@ Usage with an IO-like object `ARGF` or `$stdin`:
115
115
  ````ruby
116
116
  # > cat filename.xml | ruby this_script.rb
117
117
  Saxy.parse(ARGF, "product").each do |product|
118
- puts product.name
118
+ puts product["name"]
119
119
  end
120
120
 
121
121
  # =>
@@ -141,7 +141,7 @@ Multiple definitions of child objects are grouped in arrays:
141
141
 
142
142
  ````ruby
143
143
  webstore = Saxy.parse("filename.xml", "webstore").first
144
- webstore[:products][:product].size # => 2
144
+ webstore["products"]["product"].size # => 2
145
145
  ````
146
146
 
147
147
  ## Debugging
@@ -23,23 +23,23 @@ module Saxy
23
23
  def to_h
24
24
  return value unless attributes.any?
25
25
  data = attributes.reduce({}) do |memo, (name, value)|
26
- memo[name.to_sym] = value.size == 1 ? value.first : value
26
+ memo[name] = value.size == 1 ? value.first : value
27
27
  memo
28
28
  end
29
- data[:contents] = value
29
+ data["contents"] = value
30
30
  data
31
31
  end
32
32
 
33
33
  def attribute_name(name)
34
- underscore(name).to_sym
34
+ underscore(name)
35
35
  end
36
36
 
37
37
  private
38
38
 
39
39
  def underscore(word)
40
40
  word = word.dup
41
- word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
42
- word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
41
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
42
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
43
43
  word.tr!("-", "_")
44
44
  word.downcase!
45
45
  word
@@ -1,3 +1,3 @@
1
1
  module Saxy
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -23,8 +23,8 @@ describe Saxy::Element do
23
23
  expect(element).to receive(:attributes).at_least(:once).and_return("foo" => 1, "bar" => 2)
24
24
  object = element.to_h
25
25
 
26
- expect(object[:foo]).to eq(1)
27
- expect(object[:bar]).to eq(2)
26
+ expect(object["foo"]).to eq(1)
27
+ expect(object["bar"]).to eq(2)
28
28
  end
29
29
 
30
30
  it "should dump as object with value when attributes and contents are set" do
@@ -32,18 +32,18 @@ describe Saxy::Element do
32
32
  element.append_value("value")
33
33
  object = element.to_h
34
34
 
35
- expect(object[:foo]).to eq("bar")
36
- expect(object[:contents]).to eq("value")
35
+ expect(object["foo"]).to eq("bar")
36
+ expect(object["contents"]).to eq("value")
37
37
  end
38
38
 
39
39
  it "should add attributes under underscored names" do
40
40
  element.set_attribute("FooBar", "baz")
41
- expect(element.to_h[:foo_bar]).to eq("baz")
41
+ expect(element.to_h["foo_bar"]).to eq("baz")
42
42
  end
43
43
 
44
44
  it "should create array if adding multiple attributtes with the same name" do
45
45
  element.set_attribute("foo", "bar")
46
46
  element.set_attribute("foo", "baz")
47
- expect(element.to_h[:foo]).to eq(["bar", "baz"])
47
+ expect(element.to_h["foo"]).to eq(["bar", "baz"])
48
48
  end
49
49
  end
@@ -161,7 +161,7 @@ describe Saxy::Parser do
161
161
 
162
162
  it "should set element's attributes when opening tag with attributes" do
163
163
  parser.start_element("foo", [["bar", "baz"]])
164
- expect(parser.current_element.to_h[:bar]).to eq("baz")
164
+ expect(parser.current_element.to_h["bar"]).to eq("baz")
165
165
  end
166
166
  end
167
167
 
@@ -9,26 +9,26 @@ describe Saxy do
9
9
  arr
10
10
  end
11
11
 
12
- expect(products[0][:uid]).to eq("FFCF177")
13
- expect(products[0][:name]).to eq("Kindle")
14
- expect(products[0][:description]).to eq("The world's best-selling e-reader.")
15
- expect(products[0][:price]).to eq("$109")
16
- expect(products[0][:images][:thumb]).to eq("http://amazon.com/kindle_thumb.jpg")
17
- expect(products[0][:images][:large]).to eq("http://amazon.com/kindle.jpg")
18
-
19
- expect(products[1][:uid]).to eq("YD26NT")
20
- expect(products[1][:name]).to eq("Kindle Touch")
21
- expect(products[1][:description]).to eq("Simple-to-use touchscreen with built-in WIFI.")
22
- expect(products[1][:price]).to eq("$79")
23
- expect(products[1][:images][:thumb]).to eq("http://amazon.com/kindle_touch_thumb.jpg")
24
- expect(products[1][:images][:large]).to eq("http://amazon.com/kindle_touch.jpg")
12
+ expect(products[0]["uid"]).to eq("FFCF177")
13
+ expect(products[0]["name"]).to eq("Kindle")
14
+ expect(products[0]["description"]).to eq("The world's best-selling e-reader.")
15
+ expect(products[0]["price"]).to eq("$109")
16
+ expect(products[0]["images"]["thumb"]).to eq("http://amazon.com/kindle_thumb.jpg")
17
+ expect(products[0]["images"]["large"]).to eq("http://amazon.com/kindle.jpg")
18
+
19
+ expect(products[1]["uid"]).to eq("YD26NT")
20
+ expect(products[1]["name"]).to eq("Kindle Touch")
21
+ expect(products[1]["description"]).to eq("Simple-to-use touchscreen with built-in WIFI.")
22
+ expect(products[1]["price"]).to eq("$79")
23
+ expect(products[1]["images"]["thumb"]).to eq("http://amazon.com/kindle_touch_thumb.jpg")
24
+ expect(products[1]["images"]["large"]).to eq("http://amazon.com/kindle_touch.jpg")
25
25
  end
26
26
 
27
27
  it "should group multiple definitions of child objects into arrays" do
28
28
  webstore = Saxy.parse(fixture_file("webstore.xml"), "webstore").first
29
29
 
30
- expect(webstore[:products][:product]).to be_an(Array)
31
- expect(webstore[:products][:product].size).to eq(2)
30
+ expect(webstore["products"]["product"]).to be_an(Array)
31
+ expect(webstore["products"]["product"].size).to eq(2)
32
32
  end
33
33
 
34
34
  it "should return Enumerator when calling #parse without a block" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.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: 2017-08-23 00:00:00.000000000 Z
11
+ date: 2017-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri