Class: MacroObject

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

Direct Known Subclasses

Action, Constraint, Trigger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h = {}) ⇒ MacroObject

Returns a new instance of MacroObject.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/ruby-macrodroid/base.rb', line 115

def initialize(h={})
  
  $env ||= {}
  
  @attributes = i(constraint_list is_or_condition is_disabled siguid)
  @h = {constraint_list: [], is_or_condition: false, 
        is_disabled: false, siguid: nil}.merge(h)
  @list = []
  
  # fetch the class name and convert from camelCase to snake_eyes
  @type = self.class.to_s.sub(/Trigger|Action$/,'')\
      .gsub(/\B[A-Z][a-z]/){|x| '_' + x.downcase}\
      .gsub(/[a-z][A-Z]/){|x| x[0] + '_' + x[1].downcase}\
      .downcase.to_sym
  @constraints = []
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



113
114
115
# File 'lib/ruby-macrodroid/base.rb', line 113

def options
  @options
end

#siguidObject (readonly)

Returns the value of attribute siguid.



112
113
114
# File 'lib/ruby-macrodroid/base.rb', line 112

def siguid
  @siguid
end

#typeObject (readonly)

Returns the value of attribute type.



112
113
114
# File 'lib/ruby-macrodroid/base.rb', line 112

def type
  @type
end

Instance Method Details

#to_hObject



132
133
134
135
136
# File 'lib/ruby-macrodroid/base.rb', line 132

def to_h()

  hashify(@h)

end

#to_s(colour: false, indent: 0) ⇒ Object Also known as: to_summary



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/ruby-macrodroid/base.rb', line 142

def to_s(colour: false, indent: 0)
  
  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)}
  
  out = []
  out << "; %s" % @h[:comment] if @h[:comment] and @h[:comment].length > 1
  #s = @s.lines.map {|x| 'x' + x}.join
  
  lines = @s.lines
  
  if lines.length > 1 then        
    s = lines[0] + lines[1..-1].map {|x| x.prepend ('  ' * (indent+1)) }.join
  else
    s = @s
  end
  
  out << s
  out += constraints
  out.join("\n")
  
end