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.
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 |
# File 'lib/ruby-macrodroid.rb', line 1545 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
1586 1587 1588 1589 1590 |
# File 'lib/ruby-macrodroid.rb', line 1586 def match?(detail={time: $env[:time]}, model=nil) time() == detail[:time] end |
#set_env ⇒ Object
sets the environmental conditions for this trigger to fire
1594 1595 1596 |
# File 'lib/ruby-macrodroid.rb', line 1594 def set_env() $env[:time] = time() end |
#to_pc ⇒ Object
1598 1599 1600 |
# File 'lib/ruby-macrodroid.rb', line 1598 def to_pc() "time.is? '%s'" % self.to_s.gsub(',', ' or') end |
#to_s ⇒ Object
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 |
# File 'lib/ruby-macrodroid.rb', line 1602 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 |