Class: Action

Inherits:
MacroObject show all
Defined in:
lib/ruby-macrodroid/actions.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 = {}) ⇒ Action

Returns a new instance of Action.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ruby-macrodroid/actions.rb', line 40

def initialize(h={}) 
  
  macro = h[:macro]
  h.delete :macro
  super(h)
  
  # fetch the constraints                               
  @constraints = @h[:constraint_list].map do |constraint|
    object(constraint.to_snake_case.merge(macro: macro))
  end       
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



38
39
40
# File 'lib/ruby-macrodroid/actions.rb', line 38

def constraints
  @constraints
end

Instance Method Details

#invoke(s = '') ⇒ Object



52
53
54
# File 'lib/ruby-macrodroid/actions.rb', line 52

def invoke(s='')    
  "%s/%s: %s" % [@group, @type, s]
end

#to_s(colour: false) ⇒ Object



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

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| x.to_summary(colour: colour)}.join(" %s " % operator)
  
  @s + constraints
  
end