Class: TimerTrigger
- Inherits:
-
Trigger
- Object
- MacroObject
- Trigger
- TimerTrigger
- Defined in:
- lib/ruby-macrodroid.rb
Overview
Category: Date/Time
Instance Attribute Summary
Attributes inherited from MacroObject
Instance Method Summary collapse
-
#initialize(h = {}) ⇒ TimerTrigger
constructor
A new instance of TimerTrigger.
- #match?(detail = {time: $env[:time]}) ⇒ Boolean
Methods inherited from MacroObject
Constructor Details
#initialize(h = {}) ⇒ TimerTrigger
Returns a new instance of TimerTrigger.
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 |
# File 'lib/ruby-macrodroid.rb', line 974 def initialize(h={}) puts 'TimerTrigger h: ' + h.inspect if $debug if h[:days] then days = [false] * 7 h[:days].split(/, */).each do |x| r = Date::DAYNAMES.grep /#{x}/i i = Date::DAYNAMES.index(r.first) days[i-1] = true end h[:days_of_week] = days end if h[:time] then t = Time.parse(h[:time]) h[:hour], h[:minute] = t.hour, t.min end #puts ('h: ' + h.inspect).debug = { alarm_id: uuid(), days_of_week: [false, false, false, false, false, false, false], minute: 10, hour: 7, use_alarm: false } super(.merge filter(,h)) end |
Instance Method Details
#match?(detail = {time: $env[:time]}) ⇒ Boolean
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 |
# File 'lib/ruby-macrodroid.rb', line 1015 def match?(detail={time: $env[:time]}) a = @h[:days_of_week] a.unshift a.pop dow = a.map.with_index {|x, i| x ? i : nil }.compact.join(',') s = "%s %s * * %s" % [@h[:minute], @h[:hour], dow] if $debug then puts 's: ' + s.inspect puts 'detail: ' + detail.inspect puts '@h: ' + @h.inspect end ChronicCron.new(s, detail[:time]).to_time == detail[:time] end |