Class: Wristwatch::Schedule

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Intervals
Defined in:
lib/wristwatch/schedule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Intervals

#annually, #bi_daily, #bi_hourly, #bi_monthly, #bi_weekly, #daily, #hourly, #monthly, #quarter_hourly, #quarterly, #semiannually, #weekly

Constructor Details

#initialize(time = Time.now) ⇒ Schedule

Returns a new instance of Schedule.



8
9
10
# File 'lib/wristwatch/schedule.rb', line 8

def initialize(time = Time.now)
  @now = time
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/wristwatch/schedule.rb', line 26

def method_missing(meth, *args, &blk)
  if meth.to_s[meth.to_s.length - 1, 1] === "?"
    begin
      send(meth[0, meth.to_s.length - 1], *args, &blk)
    rescue NoMethodError
      super(meth, *args, &blk)
    end
  else
    super(meth, *args, &blk)
  end
end

Instance Attribute Details

#nowObject (readonly)

Returns the value of attribute now.



6
7
8
# File 'lib/wristwatch/schedule.rb', line 6

def now
  @now
end

Instance Method Details

#available_intervalsObject



16
17
18
# File 'lib/wristwatch/schedule.rb', line 16

def available_intervals
  Intervals.instance_methods
end

#eachObject



20
21
22
23
24
# File 'lib/wristwatch/schedule.rb', line 20

def each
  intervals.each do |interval|
    yield interval
  end
end

#intervalsObject



12
13
14
# File 'lib/wristwatch/schedule.rb', line 12

def intervals
  available_intervals.select { |interval| send(interval) }
end