Class: Trigger

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

Instance Attribute Summary collapse

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(h = {}) ⇒ Trigger

Returns a new instance of Trigger.



36
37
38
39
40
41
42
43
44
45
# File 'lib/ruby-macrodroid/triggers.rb', line 36

def initialize(h={})    
  super({fakeIcon: 0}.merge(h))
  @list << 'fakeIcon'
      
  # fetch the constraints                               
  @constraints = @h[:constraint_list].map do |constraint|
    object(constraint.to_snake_case)
  end       
  
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



34
35
36
# File 'lib/ruby-macrodroid/triggers.rb', line 34

def constraints
  @constraints
end

Instance Method Details

#match?(detail = {}, model = nil) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
# File 'lib/ruby-macrodroid/triggers.rb', line 47

def match?(detail={}, model=nil)

  # only match where the key exists in the trigger object
  detail.select {|k,v| @h.include? k }.all? {|key,value| @h[key] == value}

end

#to_s(colour: false) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruby-macrodroid/triggers.rb', line 54

def to_s(colour: false)

  h = @h.clone    
  h.delete :macro
  @s ||= "#<%s %s>" % [self.class, h.inspect]
  operator = @h[:is_or_condition] ? 'OR' : 'AND'
  constraints = @constraints.map \
      {|x| 'c: ' + x.to_summary(colour: colour, indent: 1)}.join(" %s " % operator)
  
  @constraints.any? ? @s + "\n" + constraints : @s
  super()
  
end