Class: Veezi::API::Parser
- Inherits:
-
Object
- Object
- Veezi::API::Parser
- Defined in:
- lib/veezi/api/parser.rb
Instance Method Summary collapse
-
#initialize(content_type = nil) ⇒ Parser
constructor
A new instance of Parser.
- #parse(content) ⇒ Object
Constructor Details
#initialize(content_type = nil) ⇒ Parser
Returns a new instance of Parser.
6 7 8 |
# File 'lib/veezi/api/parser.rb', line 6 def initialize(content_type = nil) @content_type = content_type || :json end |
Instance Method Details
#parse(content) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/veezi/api/parser.rb', line 10 def parse(content) case @content_type.to_sym when :xml hash = Crack::XML.parse(content) if key = hash.keys.find { |key| key =~ /ArrayOf/ } hash.fetch(key, {}).delete_if { |k,v| k.include?("xml") }.values.flatten else hash.values.first || {} end else Crack::JSON.parse(content) end end |