Class: Lighthouse::Facilities::Response
- Inherits:
-
Common::Base
- Object
- Common::Base
- Lighthouse::Facilities::Response
- Defined in:
- lib/lighthouse/facilities/response.rb
Instance Attribute Summary
Attributes inherited from Common::Base
Instance Method Summary collapse
- #facilities ⇒ Object
- #facility ⇒ Object
-
#initialize(body, status) ⇒ Response
constructor
A new instance of Response.
Methods inherited from Common::Base
#changed, #changed?, #changes, default_sort, filterable_attributes, max_per_page, per_page, sortable_attributes
Constructor Details
#initialize(body, status) ⇒ Response
Returns a new instance of Response.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lighthouse/facilities/response.rb', line 18 def initialize(body, status) super() self.body = body self.status = status parsed_body = JSON.parse(body) self.data = parsed_body['data'] self. = parsed_body['meta'] self.links = parsed_body['links'] if self.current_page = ['pagination']['current_page'] self.per_page = ['pagination']['per_page'] self.total_entries = ['pagination']['total_entries'] end end |
Instance Method Details
#facilities ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lighthouse/facilities/response.rb', line 33 def facilities facilities = data.each_with_index.map do |facility, index| fac = Lighthouse::Facilities::Facility.new(facility) fac.distance = ['distances'][index]['distance'] unless ['distances'].empty? fac end WillPaginate::Collection.create(current_page, per_page) do |pager| pager.replace(facilities) pager.total_entries = total_entries end end |
#facility ⇒ Object
46 47 48 |
# File 'lib/lighthouse/facilities/response.rb', line 46 def facility Lighthouse::Facilities::Facility.new(data) end |