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(colour: false) ⇒ Object (also: #to_summary)
Methods inherited from MacroObject
Constructor Details
#initialize(h = {}) ⇒ TimerTrigger
Returns a new instance of TimerTrigger.
1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 |
# File 'lib/ruby-macrodroid.rb', line 1831 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 @options = { alarm_id: uuid(), days_of_week: [false, false, false, false, false, false, false], minute: 10, hour: 7, use_alarm: false } #super(options.merge filter(options, h)) super(@options.merge h) end |
Instance Method Details
#match?(detail = {time: $env[:time]}, model = nil) ⇒ Boolean
1873 1874 1875 1876 1877 |
# File 'lib/ruby-macrodroid.rb', line 1873 def match?(detail={time: $env[:time]}, model=nil) time() == detail[:time] end |
#set_env ⇒ Object
sets the environmental conditions for this trigger to fire
1881 1882 1883 |
# File 'lib/ruby-macrodroid.rb', line 1881 def set_env() $env[:time] = time() end |
#to_pc ⇒ Object
1885 1886 1887 |
# File 'lib/ruby-macrodroid.rb', line 1885 def to_pc() "time.is? '%s'" % self.to_s.gsub(',', ' or') end |
#to_s(colour: false) ⇒ Object Also known as: to_summary
1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 |
# File 'lib/ruby-macrodroid.rb', line 1889 def to_s(colour: false) dow = @h[:days_of_week] wd = Date::ABBR_DAYNAMES a = (wd[1..-1] << wd.first) a2 = dow.map.with_index.to_a start = a2.find {|x,i| x}.last r = a2[start..-1].take_while {|x,i| x == true} r2 = a2[start..-1].select {|x,i| x} days = if r == r2 then x1, x2 = a2[start].last, a2[r.length-1].last if (x2 - x1) >= 2 then "%s-%s" % [a[x1],a[x2]] else a.zip(dow).select {|_,b| b}.map(&:first).join(', ') end else a.zip(dow).select {|_,b| b}.map(&:first).join(', ') end time = Time.parse("%s:%s" % [@h[:hour], @h[:minute]]).strftime("%H:%M") "%s %s" % [time, days] end |