Class: Interpreter
- Inherits:
-
Object
- Object
- Interpreter
- Defined in:
- lib/soaspec/interpreter.rb
Overview
Help interpret the general type of a particular object
Class Method Summary collapse
-
.json? ⇒ Boolean
Whether valid JSON.
-
.response_type_for(response) ⇒ Symbol
Type of provided response.
-
.xml? ⇒ Boolean
Whether valid XML.
Class Method Details
.json? ⇒ Boolean
Returns Whether valid JSON.
35 36 37 38 39 |
# File 'lib/soaspec/interpreter.rb', line 35 def json? JSON.parse(@response) rescue JSON::ParserError false end |
.response_type_for(response) ⇒ Symbol
Returns Type of provided response.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/soaspec/interpreter.rb', line 8 def response_type_for(response) @response = response if @response.is_a? String if xml? :xml elsif json? :json else :unknown end elsif response.is_a? Hash :hash elsif response.is_a? Nokogiri::XML::NodeSet :xml else :unknown end end |
.xml? ⇒ Boolean
Returns Whether valid XML.
28 29 30 31 32 |
# File 'lib/soaspec/interpreter.rb', line 28 def xml? Nokogiri::XML(@response) { |config| config. = Nokogiri::XML::ParseOptions::STRICT } rescue Nokogiri::XML::SyntaxError false end |