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 +4 -4
- data/lib/badgerfish/ox_sax_parser.rb +22 -14
- data/lib/badgerfish/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 701b8ae82afa8d6022fb905415e5131a93854b41
|
4
|
+
data.tar.gz: eded2895524d80adb427681cfab22af0ad8c6787
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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]
|
41
|
+
@root[name] << new_element
|
35
42
|
end
|
36
43
|
|
37
|
-
@parents
|
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 |
|
43
|
-
|
44
|
-
|
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
|
-
|
51
|
-
@
|
52
|
-
|
53
|
-
@root['@xmlns'] ||= {}
|
56
|
+
if name.to_s.start_with?('xmlns')
|
57
|
+
unless @remove_namespaces
|
58
|
+
@root['@xmlns'] ||= {}
|
54
59
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
|
data/lib/badgerfish/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ox
|