Class: Charging::Collection
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Charging::Collection
- Defined in:
- lib/charging/collection.rb
Overview
Represents a object collection result. It is a delegator for an array of object.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#last_response ⇒ Object
readonly
Responds the last http response from the API.
Instance Method Summary collapse
-
#initialize(response, attributes) ⇒ Collection
constructor
:nodoc:.
-
#load_data_with_response! ⇒ Object
:nodoc:.
Constructor Details
#initialize(response, attributes) ⇒ Collection
:nodoc:
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/charging/collection.rb', line 10 def initialize(response, attributes) # :nodoc: Helpers.required_arguments!(attributes.merge('response' => response)) @last_response = response attributes.each do |attribute, value| instance_variable_set("@#{attribute}", value) end super(load_data_with_response!) end |
Instance Attribute Details
#last_response ⇒ Object (readonly)
Responds the last http response from the API.
8 9 10 |
# File 'lib/charging/collection.rb', line 8 def last_response @last_response end |
Instance Method Details
#load_data_with_response! ⇒ Object
:nodoc:
22 23 24 25 26 27 |
# File 'lib/charging/collection.rb', line 22 def load_data_with_response! # :nodoc: return [] if last_response.code != 200 raw_lines = MultiJson.decode(last_response.body) raw_lines.map { |raw_line| load_object_with(raw_line) } end |