Class: Macro

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(debug: false) ⇒ Macro

Returns a new instance of Macro.



38
39
40
41
42
43
# File 'lib/ruby-macrodroid.rb', line 38

def initialize(debug: false)

  @debug = debug
  lv=[], triggers=[], actions=[]
  @local_variables, @triggers, @actions = lv, triggers, actions
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



36
37
38
# File 'lib/ruby-macrodroid.rb', line 36

def actions
  @actions
end

#guidObject (readonly)

Returns the value of attribute guid.



36
37
38
# File 'lib/ruby-macrodroid.rb', line 36

def guid
  @guid
end

#local_variablesObject (readonly)

Returns the value of attribute local_variables.



36
37
38
# File 'lib/ruby-macrodroid.rb', line 36

def local_variables
  @local_variables
end

#triggersObject (readonly)

Returns the value of attribute triggers.



36
37
38
# File 'lib/ruby-macrodroid.rb', line 36

def triggers
  @triggers
end

Instance Method Details

#import_h(h) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ruby-macrodroid.rb', line 57

def import_h(h)

  # fetch the local variables
  @local_variables = h['localVariables']
  
  # fetch the triggers
  @triggers = h['m_triggerList'].map do |trigger|
    
    object(trigger.to_params)

  end

  @actions = h['m_actionList'].map do |action|
    object(action.to_params)
  end

  # fetch the constraints (not yet implemented)
  
  @h = h

  %w(localVariables m_triggerList m_actionList).each do |x|
    @h[x] = []
  end

  @h

end

#to_hObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ruby-macrodroid.rb', line 45

def to_h()

  h = {
    'localVariables' => @local_variables,
    'm_triggerList' => @triggers.map(&:to_h),
    'm_actionList' => @actions.map(&:to_h),
    'm_constraintList' =>[]
  }  

  @h.merge(h)
end