Class: UN::Data::ResponseParser
- Inherits:
-
Object
- Object
- UN::Data::ResponseParser
- Defined in:
- lib/un/data/response_parser.rb
Instance Method Summary collapse
- #check_for_errors(document) ⇒ Object
-
#initialize(options = {}) ⇒ ResponseParser
constructor
A new instance of ResponseParser.
- #parse_data_sets(data) ⇒ Object
- #parse_filter_query(data) ⇒ Object
- #parse_query_results(data) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ResponseParser
Returns a new instance of ResponseParser.
32 33 |
# File 'lib/un/data/response_parser.rb', line 32 def initialize(={}) end |
Instance Method Details
#check_for_errors(document) ⇒ Object
35 36 37 38 39 |
# File 'lib/un/data/response_parser.rb', line 35 def check_for_errors(document) document.elements.each("/error") do |element| raise element.text end end |
#parse_data_sets(data) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/un/data/response_parser.rb', line 41 def parse_data_sets(data) document = REXML::Document.new data check_for_errors document result = [] document.elements.each("/datasets/dataset") do |element| result << OpenStruct.new(:organisation => element.attributes['organisation'], :category => element.attributes['category'], :name => element.attributes['name']) end result end |
#parse_filter_query(data) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/un/data/response_parser.rb', line 78 def parse_filter_query(data) document = REXML::Document.new data check_for_errors document result = [] document.elements.each("/data/record") do |element| fields ={} element.elements.each do |e| fields[e.attributes['name']] = e.text end result << QueryResult.new(fields) end result end |
#parse_query_results(data) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/un/data/response_parser.rb', line 57 def parse_query_results(data) document = REXML::Document.new data check_for_errors document result = [] document.elements.each("/data/record") do |element| fields ={} element.elements.each do |e| fields[e.attributes['name']] = e.text end result << QueryResult.new(fields) end result end |