Class: TimerTrigger
- Inherits:
-
Trigger
- Object
- MacroObject
- Trigger
- TimerTrigger
- Defined in:
- lib/ruby-macrodroid.rb
Overview
Category: Date/Time
Instance Attribute Summary
Attributes inherited from Trigger
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.
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 |
# File 'lib/ruby-macrodroid.rb', line 1610 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
1651 1652 1653 1654 1655 |
# File 'lib/ruby-macrodroid.rb', line 1651 def match?(detail={time: $env[:time]}, model=nil) time() == detail[:time] end |
#set_env ⇒ Object
sets the environmental conditions for this trigger to fire
1659 1660 1661 |
# File 'lib/ruby-macrodroid.rb', line 1659 def set_env() $env[:time] = time() end |
#to_pc ⇒ Object
1663 1664 1665 |
# File 'lib/ruby-macrodroid.rb', line 1663 def to_pc() "time.is? '%s'" % self.to_s.gsub(',', ' or') end |
#to_s ⇒ Object
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 |
# File 'lib/ruby-macrodroid.rb', line 1667 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 |