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]}, model = nil) ⇒ Boolean
- #to_pc ⇒ Object
- #to_s ⇒ Object
Methods inherited from MacroObject
Constructor Details
#initialize(h = {}) ⇒ TimerTrigger
Returns a new instance of TimerTrigger.
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 |
# File 'lib/ruby-macrodroid.rb', line 1171 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]}, model = nil) ⇒ Boolean
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 |
# File 'lib/ruby-macrodroid.rb', line 1212 def match?(detail={time: $env[:time]}, model=nil) 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 |
#to_pc ⇒ Object
1231 1232 1233 |
# File 'lib/ruby-macrodroid.rb', line 1231 def to_pc() "time.is? '%s'" % self.to_s.gsub(',', ' or') end |
#to_s ⇒ Object
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 |
# File 'lib/ruby-macrodroid.rb', line 1235 def to_s() dow = @h[:days_of_week] a = Date::ABBR_DAYNAMES time = Time.parse("%s:%s" % [@h[:hour], @h[:minute]]).strftime("%-H:%M%P") days = (a[1..-1] << a.first).zip(dow).select {|_,b| b}.map(&:first) "at %s on %s" % [time, days.join(', ')] end |