Class: Action

Inherits:
MacroObject show all
Defined in:
lib/ruby-macrodroid.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.



2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
# File 'lib/ruby-macrodroid.rb', line 2775

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.



2773
2774
2775
# File 'lib/ruby-macrodroid.rb', line 2773

def constraints
  @constraints
end

Instance Method Details

#invoke(s = '') ⇒ Object



2787
2788
2789
# File 'lib/ruby-macrodroid.rb', line 2787

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

#to_s(colour: false) ⇒ Object



2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
# File 'lib/ruby-macrodroid.rb', line 2791

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