Class: GreenButtonData::IntervalBlock
- Includes:
- Utilities
- Defined in:
- lib/green-button-data/interval_block.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#ends_at ⇒ Object
Returns the value of attribute ends_at.
-
#length ⇒ Object
Returns the value of attribute length.
-
#starts_at ⇒ Object
Returns the value of attribute starts_at.
Attributes inherited from Entry
Instance Method Summary collapse
-
#initialize(attributes) ⇒ IntervalBlock
constructor
A new instance of IntervalBlock.
-
#to_a ⇒ Object
Returns an array representation of all the interval data.
Methods included from Utilities
#attributes_to_hash, #class_from_name, #epoch_to_time, #first_sunday_of, #last_weekday_of, #normalize_epoch, #nth_weekday_of, #parse_datetime, #weekday_offset
Methods included from Fetchable
Constructor Details
#initialize(attributes) ⇒ IntervalBlock
Returns a new instance of IntervalBlock.
7 8 9 10 11 12 13 14 |
# File 'lib/green-button-data/interval_block.rb', line 7 def initialize(attributes) super @starts_at = @interval.starts_at local: true @ends_at = @interval.ends_at local: true @duration = @interval.duration @length = @interval_readings.size end |
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration.
5 6 7 |
# File 'lib/green-button-data/interval_block.rb', line 5 def duration @duration end |
#ends_at ⇒ Object
Returns the value of attribute ends_at.
5 6 7 |
# File 'lib/green-button-data/interval_block.rb', line 5 def ends_at @ends_at end |
#length ⇒ Object
Returns the value of attribute length.
5 6 7 |
# File 'lib/green-button-data/interval_block.rb', line 5 def length @length end |
#starts_at ⇒ Object
Returns the value of attribute starts_at.
5 6 7 |
# File 'lib/green-button-data/interval_block.rb', line 5 def starts_at @starts_at end |
Instance Method Details
#to_a ⇒ Object
Returns an array representation of all the interval data
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/green-button-data/interval_block.rb', line 18 def to_a result = [] @interval_readings.each do |interval_reading| reading = { starts_at: interval_reading.time_period.starts_at(local: true), ends_at: interval_reading.time_period.ends_at(local: true), duration: interval_reading.time_period.duration, value: interval_reading.value } reading[:cost] = interval_reading.cost if interval_reading.cost reading[:quality] = interval_reading.quality if interval_reading.quality reading[:tou] = interval_reading.tou if interval_reading.tou result << reading end return result end |