Class: OXMLRPC::Parser
- Inherits:
-
Ox::Sax
- Object
- Ox::Sax
- OXMLRPC::Parser
- Defined in:
- lib/oxmlrpc/parser.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#rpc_method ⇒ Object
readonly
Returns the value of attribute rpc_method.
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_params(value) ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #start_element(name) ⇒ Object
- #text(value) ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
14 15 16 17 18 19 20 |
# File 'lib/oxmlrpc/parser.rb', line 14 def initialize @elements = [] @rpc_method = nil @params = [] @array_mode = false @struct_mode = false end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/oxmlrpc/parser.rb', line 6 def params @params end |
#rpc_method ⇒ Object (readonly)
Returns the value of attribute rpc_method.
6 7 8 |
# File 'lib/oxmlrpc/parser.rb', line 6 def rpc_method @rpc_method end |
Class Method Details
.parse(xml) ⇒ Object
8 9 10 11 12 |
# File 'lib/oxmlrpc/parser.rb', line 8 def self.parse(xml) parser = self.new Ox.sax_parse(parser, StringIO.new(xml)) parser end |
Instance Method Details
#add_to_params(value) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/oxmlrpc/parser.rb', line 54 def add_to_params(value) if @array_mode @params.last << value elsif @struct_mode @params.last[@params.last.keys.last] = value else @params << value end end |
#end_element(name) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/oxmlrpc/parser.rb', line 36 def end_element(name) @array_mode = false if :array == name @struct_mode = false if :struct == name raise "Invalid XML" unless @elements.pop == name end |
#start_element(name) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/oxmlrpc/parser.rb', line 22 def start_element(name) @elements << name if :array == name @array_mode = true @params << Array.new end if :struct == name @struct_mode = true @params << Hash.new end end |
#text(value) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/oxmlrpc/parser.rb', line 43 def text(value) @rpc_method = value if :methodName == @elements.last @params.last[value] = nil if :name == @elements.last && @struct_mode add_to_params value == 1 || value == "1" if :boolean == @elements.last add_to_params value if [:value, :string].include?(@elements.last) add_to_params Integer(value) if [:int, :i4].include?(@elements.last) add_to_params Float(value) if :double == @elements.last add_to_params Time.parse(value) if :'dateTime.iso8601' == @elements.last end |