Class: Parsers
- Inherits:
-
Object
- Object
- Parsers
- Defined in:
- lib/dagger/parsers.rb
Instance Method Summary collapse
- #application_json(body) ⇒ Object (also: #text_javascript, #application_x_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 11 12 |
# File 'lib/dagger/parsers.rb', line 7 def initialize(response) if type = response.content_type @normalized_type = type.split(';').first.gsub(/[^a-z]/, '_') @body = response.body end end |
Instance Method Details
#application_json(body) ⇒ Object Also known as: text_javascript, application_x_javascript
18 19 20 21 22 |
# File 'lib/dagger/parsers.rb', line 18 def application_json(body) Oj.load(body) rescue Oj::ParseError nil end |
#process ⇒ Object
14 15 16 |
# File 'lib/dagger/parsers.rb', line 14 def process send(@normalized_type, @body) if @normalized_type && respond_to?(@normalized_type) end |
#text_xml(body) ⇒ Object Also known as: application_xml
27 28 29 30 31 32 33 |
# File 'lib/dagger/parsers.rb', line 27 def text_xml(body) if res = Ox.parse(body) res.to_node end rescue Ox::ParseError nil end |