saxerator 0.7.0 → 0.7.1

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.
data/README.md CHANGED
@@ -88,9 +88,10 @@ Saxerator.parse(xml) do |config|
88
88
  end
89
89
  ```
90
90
 
91
- | Config Option | 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`
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/rubiii/nori) and [Gregory Brown](http://majesticseacreature.com/)'s
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 ####
@@ -5,7 +5,7 @@ module Saxerator
5
5
 
6
6
  def initialize(config, name, attributes)
7
7
  @config = config
8
- @name = name
8
+ @name = config.hash_key_generator.call(name)
9
9
  @attributes = attributes
10
10
  @children = []
11
11
  @text = false
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Saxerator
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -37,21 +37,32 @@ describe Saxerator do
37
37
  end
38
38
  end
39
39
 
40
- context "output_type configuration" do
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 "with config.output_type = :hash" do
48
- let(:output_type) { :hash }
49
- specify { parser.all.should == {'bar' => 'baz'} }
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 "with an invalid config.output_type" do
53
- let(:output_type) { 'lmao' }
54
- specify { lambda { parser }.should raise_error(ArgumentError) }
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.0
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-09-21 00:00:00.000000000 Z
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri