Class: SitraResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/sitra_client/sitra_response.rb

Instance Method Summary collapse

Constructor Details

#initializeSitraResponse

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_arrayObject



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_hashObject



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_jsonObject



31
32
33
# File 'lib/sitra_client/sitra_response.rb', line 31

def as_raw_json
  @json_response
end

#results_countObject



20
21
22
# File 'lib/sitra_client/sitra_response.rb', line 20

def results_count
  as_hash[:numFound]
end

#returned_countObject



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