Class: GreenButtonData::IntervalBlock

Inherits:
Entry
  • Object
show all
Includes:
Utilities
Defined in:
lib/green-button-data/interval_block.rb

Instance Attribute Summary collapse

Attributes inherited from Entry

#id, #token, #usage_point_id

Instance Method Summary collapse

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

included

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

#durationObject

Returns the value of attribute duration.



5
6
7
# File 'lib/green-button-data/interval_block.rb', line 5

def duration
  @duration
end

#ends_atObject

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

#lengthObject

Returns the value of attribute length.



5
6
7
# File 'lib/green-button-data/interval_block.rb', line 5

def length
  @length
end

#starts_atObject

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_aObject

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