Class: OasParser::ResponseParser
- Inherits:
-
Object
- Object
- OasParser::ResponseParser
- Defined in:
- lib/oas_parser/response_parser.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
-
#initialize(raw) ⇒ ResponseParser
constructor
A new instance of ResponseParser.
- #json ⇒ Object
- #parse(mode = nil) ⇒ Object
- #xml(xml_options = {}) ⇒ Object
Constructor Details
#initialize(raw) ⇒ ResponseParser
Returns a new instance of ResponseParser.
5 6 7 |
# File 'lib/oas_parser/response_parser.rb', line 5 def initialize(raw) @raw = raw end |
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
3 4 5 |
# File 'lib/oas_parser/response_parser.rb', line 3 def raw @raw end |
Instance Method Details
#json ⇒ Object
14 15 16 |
# File 'lib/oas_parser/response_parser.rb', line 14 def json parse('json').to_json end |
#parse(mode = nil) ⇒ Object
9 10 11 12 |
# File 'lib/oas_parser/response_parser.rb', line 9 def parse(mode = nil) @mode = mode route(@raw) end |
#xml(xml_options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/oas_parser/response_parser.rb', line 18 def xml( = {}) ||= {} = .merge() raw_xml = parse('xml').to_xml() xml_document = Nokogiri::XML(raw_xml) xml_document.xpath('//__attributes').each do |attributes| attributes.children.each do |attribute| next unless attribute.class == Nokogiri::XML::Element attribute.parent.parent.css("> #{attribute.name}").remove attribute.parent.parent[attribute.name] = attribute.content end end xml_document.xpath('//__text').each do |attribute| value = attribute.children.last.content attribute.parent.content = value end xml_document.xpath('//__attributes').each(&:remove) xml_document.to_xml.each_line.reject { |x| x.strip == '' }.join end |