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
-
#set_env ⇒ Object
sets the environmental conditions for this trigger to fire.
- #to_pc ⇒ Object
- #to_s ⇒ Object
Methods inherited from MacroObject
Constructor Details
#initialize(h = {}) ⇒ TimerTrigger
Returns a new instance of TimerTrigger.
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 |
# File 'lib/ruby-macrodroid.rb', line 1423 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
1464 1465 1466 1467 1468 |
# File 'lib/ruby-macrodroid.rb', line 1464 def match?(detail={time: $env[:time]}, model=nil) time() == detail[:time] end |
#set_env ⇒ Object
sets the environmental conditions for this trigger to fire
1472 1473 1474 |
# File 'lib/ruby-macrodroid.rb', line 1472 def set_env() $env[:time] = time() end |
#to_pc ⇒ Object
1476 1477 1478 |
# File 'lib/ruby-macrodroid.rb', line 1476 def to_pc() "time.is? '%s'" % self.to_s.gsub(',', ' or') end |
#to_s ⇒ Object
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 |
# File 'lib/ruby-macrodroid.rb', line 1480 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 |