Class: TimexDatalinkClient::Protocol7::Eeprom::Calendar::Event

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Helpers::LsbMsbFormatter
Defined in:
lib/timex_datalink_client/protocol_7/eeprom/calendar/event.rb

Constant Summary collapse

FIVE_MINUTES_SECONDS =
300

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::LsbMsbFormatter

#lsb_msb_format_for

Constructor Details

#initialize(time:, phrase:) ⇒ Event

Create an Event instance.

Parameters:

  • time (::Time)

    Time of event.

  • phrase (Array<Integer>)

    Phrase for event.

Raises:

  • (ActiveModel::ValidationError)

    One or more model values are invalid.



30
31
32
33
# File 'lib/timex_datalink_client/protocol_7/eeprom/calendar/event.rb', line 30

def initialize(time:, phrase:)
  @time = time
  @phrase = phrase
end

Instance Attribute Details

#device_timeObject

Returns the value of attribute device_time.



22
23
24
# File 'lib/timex_datalink_client/protocol_7/eeprom/calendar/event.rb', line 22

def device_time
  @device_time
end

#phraseObject

Returns the value of attribute phrase.



22
23
24
# File 'lib/timex_datalink_client/protocol_7/eeprom/calendar/event.rb', line 22

def phrase
  @phrase
end

#timeObject

Returns the value of attribute time.



22
23
24
# File 'lib/timex_datalink_client/protocol_7/eeprom/calendar/event.rb', line 22

def time
  @time
end

Instance Method Details

#time_formatted(device_time) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/timex_datalink_client/protocol_7/eeprom/calendar/event.rb', line 35

def time_formatted(device_time)
  @device_time = device_time

  validate!

  device_time_midnight = Time.new(device_time.year, device_time.month, device_time.day)
  seconds = (time - device_time_midnight).to_i
  five_minutes = seconds / FIVE_MINUTES_SECONDS

  lsb_msb_format_for(five_minutes)
end