Class: TimerTrigger

Inherits:
Trigger show all
Defined in:
lib/ruby-macrodroid.rb

Instance Method Summary collapse

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(h = {}) ⇒ TimerTrigger

Returns a new instance of TimerTrigger.



807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
# File 'lib/ruby-macrodroid.rb', line 807

def initialize(h={})
  
  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
    h.delete :days
    
  end
  
  if h[:time] then
    
    t = Time.parse(h[:time])
    h[:hour], h[:minute] = t.hour, t.min
    h.delete :time
    
  end

  options = {
    alarm_id: uuid(),
    days_of_week: [false, true, false, false, false, false, false],
    minute: 10,
    hour: 7,
    use_alarm: false
  }

  super(options.merge h)

end