saxerator 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -4
- data/lib/saxerator/builder/hash_builder.rb +1 -1
- data/lib/saxerator/configuration.rb +9 -0
- data/lib/saxerator/version.rb +1 -1
- data/spec/lib/saxerator_spec.rb +22 -11
- metadata +2 -2
data/README.md
CHANGED
@@ -88,9 +88,10 @@ Saxerator.parse(xml) do |config|
|
|
88
88
|
end
|
89
89
|
```
|
90
90
|
|
91
|
-
|
|
92
|
-
|
93
|
-
| `output_type`
|
91
|
+
| Setting | Default | Values | Description
|
92
|
+
|:------------------|:--------|-----------------|------------
|
93
|
+
| `output_type` | `:hash` | `:hash`, `:xml` | The type of object generated by Saxerator's parsing. `:hash` should be self-explanatory, `:xml` generates a `Nokogiri::XML::Document`
|
94
|
+
| `symbolize_keys!` | n/a | n/a | Call this method if you want the hash keys to be symbols rather than strings
|
94
95
|
|
95
96
|
Known Issues
|
96
97
|
------------
|
@@ -116,7 +117,7 @@ Why not DOM parsing?
|
|
116
117
|
> document is very large, this can be an important consideration.
|
117
118
|
|
118
119
|
### Acknowledgements ###
|
119
|
-
Saxerator was inspired by - but not affiliated with - [nori](https://github.com/
|
120
|
+
Saxerator was inspired by - but not affiliated with - [nori](https://github.com/savonrb/nori) and [Gregory Brown](http://majesticseacreature.com/)'s
|
120
121
|
[Practicing Ruby](http://practicingruby.com/)
|
121
122
|
|
122
123
|
#### Legal Stuff ####
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Saxerator
|
2
2
|
class Configuration
|
3
3
|
attr_reader :output_type
|
4
|
+
attr_writer :hash_key_generator
|
4
5
|
|
5
6
|
def initialize
|
6
7
|
@output_type = :hash
|
@@ -10,5 +11,13 @@ module Saxerator
|
|
10
11
|
raise ArgumentError.new("Unknown output_type '#{val.inspect}'") unless Builder.valid?(val)
|
11
12
|
@output_type = val
|
12
13
|
end
|
14
|
+
|
15
|
+
def hash_key_generator
|
16
|
+
@hash_key_generator ||= lambda { |x| x.to_s }
|
17
|
+
end
|
18
|
+
|
19
|
+
def symbolize_keys!
|
20
|
+
@hash_key_generator = lambda { |x| x.to_sym }
|
21
|
+
end
|
13
22
|
end
|
14
23
|
end
|
data/lib/saxerator/version.rb
CHANGED
data/spec/lib/saxerator_spec.rb
CHANGED
@@ -37,21 +37,32 @@ describe Saxerator do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
context "
|
41
|
-
subject(:parser) do
|
42
|
-
Saxerator.parser(xml) { |config| config.output_type = output_type }
|
43
|
-
end
|
44
|
-
|
40
|
+
context "configuration" do
|
45
41
|
let(:xml) { "<foo><bar>baz</bar></foo>" }
|
46
42
|
|
47
|
-
context "
|
48
|
-
|
49
|
-
|
43
|
+
context "output type" do
|
44
|
+
subject(:parser) do
|
45
|
+
Saxerator.parser(xml) { |config| config.output_type = output_type }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with config.output_type = :hash" do
|
49
|
+
let(:output_type) { :hash }
|
50
|
+
specify { parser.all.should == {'bar' => 'baz'} }
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with an invalid config.output_type" do
|
54
|
+
let(:output_type) { 'lmao' }
|
55
|
+
specify { expect { parser }.to raise_error(ArgumentError) }
|
56
|
+
end
|
50
57
|
end
|
51
58
|
|
52
|
-
context "
|
53
|
-
|
54
|
-
|
59
|
+
context "symbolize keys" do
|
60
|
+
subject(:parser) do
|
61
|
+
Saxerator.parser(xml) { |config| config.symbolize_keys! }
|
62
|
+
end
|
63
|
+
|
64
|
+
specify { parser.all.should == { :bar => 'baz' } }
|
55
65
|
end
|
66
|
+
|
56
67
|
end
|
57
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saxerator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|