Class: Parsers
- Inherits:
-
Object
- Object
- Parsers
- Defined in:
- lib/dagger/parsers.rb
Instance Method Summary collapse
- #application_json(body) ⇒ Object (also: #text_javascript)
-
#initialize(response) ⇒ Parsers
constructor
A new instance of Parsers.
- #process ⇒ Object
- #text_xml(body) ⇒ Object (also: #application_xml)
Constructor Details
#initialize(response) ⇒ Parsers
Returns a new instance of Parsers.
7 8 9 10 |
# File 'lib/dagger/parsers.rb', line 7 def initialize(response) @body = response.body @normalized = response.content_type.to_s.sub('/', '_').split(';').first end |
Instance Method Details
#application_json(body) ⇒ Object Also known as: text_javascript
16 17 18 19 20 |
# File 'lib/dagger/parsers.rb', line 16 def application_json(body) Oj.load(body) rescue Oj::ParseError nil end |
#process ⇒ Object
12 13 14 |
# File 'lib/dagger/parsers.rb', line 12 def process send(@normalized, @body) if respond_to?(@normalized) end |
#text_xml(body) ⇒ Object Also known as: application_xml
24 25 26 27 28 |
# File 'lib/dagger/parsers.rb', line 24 def text_xml(body) Ox.parse(body) rescue Ox::ParseError nil end |