Class: Jumbotron::Adapters::Cadence

Inherits:
Object
  • Object
show all
Defined in:
app/adapters/jumbotron/adapters/cadence.rb

Constant Summary collapse

UNITS =
{
  second: 1,
  seconds: 1,
  minute: 60,
  minutes: 60,
  hour: 3600,
  hours: 3600,
  day: 86_400,
  days: 86_400,
  week: 604_800,
  weeks: 604_800
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(every:, unit:) ⇒ Cadence

Returns a new instance of Cadence.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
# File 'app/adapters/jumbotron/adapters/cadence.rb', line 21

def initialize(every:, unit:)
  @every = Integer(every)
  @unit = unit.to_sym
  raise ArgumentError, "every must be positive" unless @every.positive?
  raise ArgumentError, "unknown cadence unit: #{unit}" unless UNITS.key?(@unit)
end

Instance Attribute Details

#everyObject (readonly)

Returns the value of attribute every.



19
20
21
# File 'app/adapters/jumbotron/adapters/cadence.rb', line 19

def every
  @every
end

#unitObject (readonly)

Returns the value of attribute unit.



19
20
21
# File 'app/adapters/jumbotron/adapters/cadence.rb', line 19

def unit
  @unit
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



32
33
34
# File 'app/adapters/jumbotron/adapters/cadence.rb', line 32

def ==(other)
  other.is_a?(self.class) && every == other.every && unit == other.unit
end

#hashObject



37
38
39
# File 'app/adapters/jumbotron/adapters/cadence.rb', line 37

def hash
  [self.class, every, unit].hash
end

#interval_secondsObject



28
29
30
# File 'app/adapters/jumbotron/adapters/cadence.rb', line 28

def interval_seconds
  every * UNITS.fetch(unit)
end