Module: ObjectX

Included in:
Action, Macro
Defined in:
lib/ruby-macrodroid/base.rb

Overview

This file contains the following classes:

## Object class

MacroObject

Instance Method Summary collapse

Instance Method Details

#action_to_object(ap, e, item, macro) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ruby-macrodroid/base.rb', line 13

def action_to_object(ap, e, item, macro)
  
  debug = false
  
  puts 'inside action_to_object: item.xml: ' + item.xml if debug
      
  if item.element('description') then
    
    item.xpath('description').map do |description|
      
      inner_lines = description.text.to_s.strip.lines
      puts 'inner_lines: ' + inner_lines.inspect if debug
      
      action = if e.text.to_s.strip.empty? then
        inner_lines.shift.strip
      else
        e.text.strip
      end
      
      puts 'action: ' + action.inspect if debug
      
      r = ap.find_action action          
      puts 'r: ' + r.inspect if debug
      
      if r[1].any? then
        
        macro.add r[0].new(r[1])
        
      else
        
        puts 'description: ' + description.xml.inspect if debug
        #o = r[0].new([description, self]) if r
        index = macro.actions.length
        macro.add Action.new        
        o = object_create(r[0],[description, macro]) if r
        macro.actions[index] = o
        puts 'after o' if debug
        o
        
      end
    end
    
  else
    
    action = e.text.strip
    puts 'action: ' + action.inspect if $debug
    r = ap.find_action action

    a = e.xpath('item/*')

    h = if a.any? then
      a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
    else
      {}
    end
    puts 'h: ' + h.inspect if $debug

    #r = ap.find_action action          
    #r[0].new(h.merge(macro: self)) if r
    o = object_create(r[0], h.merge(macro: macro)) if r
    macro.add o
    o
    
  end
    

end

#object_create(klass, *args) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/ruby-macrodroid/base.rb', line 81

def object_create(klass, *args)

  begin
    klass.new(*args)
  rescue
    raise MacroError, klass.to_s + ': ' + ($!).to_s
  end
end

#varify(label, value = '') ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ruby-macrodroid/base.rb', line 90

def varify(label, value='')
                      
  type = VAR_TYPES[value.class.to_s.to_sym]

  h = {
    boolean_value: false,
    decimal_value: 0.0,
    int_value: 0,
    name: label,
    string_value: '',
    type: type[0]
  }
  h[type[1]] = value
  h
  
end