ginjo-rfm 2.1.7 → 3.0.0

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.
@@ -1,81 +0,0 @@
1
- require 'rexml/parsers/sax2parser'
2
- require 'rexml/sax2listener'
3
- require 'rexml/document'
4
- require 'active_support/core_ext/object/blank'
5
- require 'stringio'
6
-
7
- # = XmlMini REXML implementation using the SAX2 parser
8
- module ActiveSupport
9
- module XmlMini_REXMLSAX
10
- extend self
11
-
12
- # Class that will build the hash while the XML document
13
- # is being parsed using streaming events.
14
- class HashBuilder
15
- include REXML::SAX2Listener
16
-
17
- CONTENT_KEY = '__content__'.freeze
18
- HASH_SIZE_KEY = '__hash_size__'.freeze
19
-
20
- attr_reader :hash
21
-
22
- def current_hash
23
- @hash_stack.last
24
- end
25
-
26
- def start_document
27
- @hash = {}
28
- @hash_stack = [@hash]
29
- end
30
-
31
- def end_document
32
- raise "Parse stack not empty!" if @hash_stack.size > 1
33
- end
34
-
35
- def error(error_message)
36
- raise error_message
37
- end
38
-
39
- def start_element(uri, name, qname, attrs = [])
40
- #puts "START_ELEMENT #{name}"
41
- #y attrs
42
- new_hash = { CONTENT_KEY => '' }.merge(Hash[attrs])
43
- new_hash[HASH_SIZE_KEY] = new_hash.size + 1
44
-
45
- case current_hash[name]
46
- when Array then current_hash[name] << new_hash
47
- when Hash then current_hash[name] = [current_hash[name], new_hash]
48
- when nil then current_hash[name] = new_hash
49
- end
50
-
51
- @hash_stack.push(new_hash)
52
- end
53
-
54
- def end_element(uri, name, qname)
55
- if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == ''
56
- current_hash.delete(CONTENT_KEY)
57
- end
58
- @hash_stack.pop
59
- end
60
-
61
- def characters(string)
62
- return unless string and current_hash[CONTENT_KEY]
63
- #puts "CHARACTERS #{string}"
64
- current_hash[CONTENT_KEY] << string
65
- end
66
-
67
- alias_method :cdata, :characters
68
- end
69
-
70
- attr_accessor :document_class
71
- self.document_class = HashBuilder
72
-
73
- def parse(data)
74
- document = self.document_class.new
75
- parser = REXML::Parsers::SAX2Parser.new(data)
76
- parser.listen(document)
77
- parser.parse
78
- document.hash
79
- end
80
- end
81
- end