badgerfish 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3812b8f2e3afef7416d2dfb2139f610e951997cf
4
- data.tar.gz: bc77518461d51d4a44937ed619744e1665bdd074
3
+ metadata.gz: 701b8ae82afa8d6022fb905415e5131a93854b41
4
+ data.tar.gz: eded2895524d80adb427681cfab22af0ad8c6787
5
5
  SHA512:
6
- metadata.gz: da1b3af22ee374f714ea8c1bf30ec0628ed4de935f2d56e3cc755dc3cc63e7b00d4bd955af068b8e121e32bf04f524fc2b8f4b285c8092b9bd1ec791b1998a75
7
- data.tar.gz: 1bc4511789ec4cbdddc7c9d50de60c8e6fea250fc2554557079bfffffc4768a0a2970beaf392e24ceeabe7ee72f02741931dfcdc3538841b87a92151f68f3307
6
+ metadata.gz: b43a9a7e27358f03e477eb3ceeb7c4456b65f7934d6fc0081c9ae0efa07315a8aacf131b805f8d58ac0b488cc49b2faf0e5b21096e33c0163473692a4df0290c
7
+ data.tar.gz: 8cbeb6ac68a3d8cab9007bbfbabe0f9e2c443b95cec5c47599b0acfc28256800c54789c18622f78a73155f30e7da14c8f57a8acd967295c238256d9c26c6acbb
@@ -14,6 +14,7 @@ module Badgerfish
14
14
  end
15
15
 
16
16
  @html_entities_coder = HTMLEntities.new
17
+ @remove_namespaces = !!options[:remove_namespaces]
17
18
  @result = @root = {}
18
19
  @parents = []
19
20
  Ox.sax_parse(self, StringIO.new(xml))
@@ -27,36 +28,43 @@ module Badgerfish
27
28
  new_element = {}
28
29
  name = name.to_s # force string representation of symbols
29
30
 
31
+ if @remove_namespaces
32
+ if colon_index = name.index(":")
33
+ name.slice!(0..colon_index)
34
+ end
35
+ end
36
+
30
37
  if @root[name].nil?
31
38
  @root[name] = new_element
32
39
  else
33
40
  @root[name] = [@root[name]] unless @root[name].is_a?(Array)
34
- @root[name].push new_element
41
+ @root[name] << new_element
35
42
  end
36
43
 
37
- @parents.push @root
44
+ @parents << @root
38
45
  @root = new_element
39
46
  end
40
47
 
41
48
  def end_element(name)
42
- (@root = @parents.pop).inject(@root) do |memo, (key, value)|
43
- memo.tap do |hash|
44
- hash[key] = nil if value.empty?
45
- end
49
+ (@root = @parents.pop).inject(@root) do |hash, (key, value)|
50
+ hash[key] = nil if value.nil? || value.empty?
51
+ hash
46
52
  end
47
53
  end
48
54
 
49
55
  def attr(name, value)
50
- unless name.to_s.start_with? 'xmlns'
51
- @root["@#{name}"] = value
52
- else
53
- @root['@xmlns'] ||= {}
56
+ if name.to_s.start_with?('xmlns')
57
+ unless @remove_namespaces
58
+ @root['@xmlns'] ||= {}
54
59
 
55
- if name.to_s.start_with? 'xmlns:'
56
- @root['@xmlns'][name[6, name.length]] = value
57
- else
58
- @root['@xmlns']['$'] = value
60
+ if name.to_s.start_with? 'xmlns:'
61
+ @root['@xmlns'][name[6, name.length]] = value
62
+ else
63
+ @root['@xmlns']['$'] = value
64
+ end
59
65
  end
66
+ else
67
+ @root["@#{name}"] = value
60
68
  end
61
69
  end
62
70
 
@@ -1,3 +1,3 @@
1
1
  module Badgerfish
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: badgerfish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Sievers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ox