Class: SitraResponse
- Inherits:
-
Object
- Object
- SitraResponse
- Defined in:
- lib/sitra_client/sitra_response.rb
Instance Method Summary collapse
- #append_line(line) ⇒ Object
- #as_array ⇒ Object
- #as_hash ⇒ Object
- #as_raw_json ⇒ Object
-
#initialize ⇒ SitraResponse
constructor
A new instance of SitraResponse.
- #results_count ⇒ Object
- #returned_count ⇒ Object
Constructor Details
#initialize ⇒ SitraResponse
Returns a new instance of SitraResponse.
7 8 9 10 |
# File 'lib/sitra_client/sitra_response.rb', line 7 def initialize @json_response = '' @response_hash = {} end |
Instance Method Details
#append_line(line) ⇒ Object
12 13 14 |
# File 'lib/sitra_client/sitra_response.rb', line 12 def append_line(line) @json_response += line unless line.nil? end |
#as_array ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/sitra_client/sitra_response.rb', line 35 def as_array if as_hash[:objetsTouristiques].nil? results = [] else results = as_hash[:objetsTouristiques].collect {|obj_hash| TouristicObject.new(obj_hash)} end results end |
#as_hash ⇒ Object
24 25 26 27 28 29 |
# File 'lib/sitra_client/sitra_response.rb', line 24 def as_hash if @response_hash.empty? @response_hash = JSON.parse @json_response, :symbolize_names => true end @response_hash end |
#as_raw_json ⇒ Object
31 32 33 |
# File 'lib/sitra_client/sitra_response.rb', line 31 def as_raw_json @json_response end |
#results_count ⇒ Object
20 21 22 |
# File 'lib/sitra_client/sitra_response.rb', line 20 def results_count as_hash[:numFound] end |
#returned_count ⇒ Object
16 17 18 |
# File 'lib/sitra_client/sitra_response.rb', line 16 def returned_count [as_hash[:query][:count], results_count - as_hash[:query][:first]].min end |