Class: Jumbotron::Adapters::Cadence
- Inherits:
-
Object
- Object
- Jumbotron::Adapters::Cadence
- 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
-
#every ⇒ Object
readonly
Returns the value of attribute every.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(every:, unit:) ⇒ Cadence
constructor
A new instance of Cadence.
- #interval_seconds ⇒ Object
Constructor Details
#initialize(every:, unit:) ⇒ Cadence
Returns a new instance of Cadence.
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
#every ⇒ Object (readonly)
Returns the value of attribute every.
19 20 21 |
# File 'app/adapters/jumbotron/adapters/cadence.rb', line 19 def every @every end |
#unit ⇒ Object (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 |
#hash ⇒ Object
37 38 39 |
# File 'app/adapters/jumbotron/adapters/cadence.rb', line 37 def hash [self.class, every, unit].hash end |
#interval_seconds ⇒ Object
28 29 30 |
# File 'app/adapters/jumbotron/adapters/cadence.rb', line 28 def interval_seconds every * UNITS.fetch(unit) end |