Class: MacroObject

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



1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
# File 'lib/ruby-macrodroid.rb', line 1116

def initialize(h={})
  
  $env ||= {}
  
  @h = {constraint_list: [], is_or_condition: false, 
        is_disabled: false}.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
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



1114
1115
1116
# File 'lib/ruby-macrodroid.rb', line 1114

def options
  @options
end

#siguidObject (readonly)

Returns the value of attribute siguid.



1113
1114
1115
# File 'lib/ruby-macrodroid.rb', line 1113

def siguid
  @siguid
end

#typeObject (readonly)

Returns the value of attribute type.



1113
1114
1115
# File 'lib/ruby-macrodroid.rb', line 1113

def type
  @type
end

Instance Method Details

#to_hObject



1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
# File 'lib/ruby-macrodroid.rb', line 1131

def to_h()

  h = @h

  h2 = h.inject({}) do |r,x|
    puts 'x: ' + x.inspect if @debug
    key, value = x
    puts 'key: ' + key.inspect if @debug
    new_key = key.to_s.gsub(/\w_\w/){|x| x[0] + x[-1].upcase}
    new_key = new_key.prepend 'm_' unless @list.include? new_key
    new_key = 'm_SIGUID' if new_key == 'm_siguid'
    r.merge(new_key => value)
  end
  
  h2.merge('m_classType' => self.class.to_s)

end

#to_sObject Also known as: to_summary



1153
1154
1155
# File 'lib/ruby-macrodroid.rb', line 1153

def to_s()
  "#<%s %s>" % [self.class, @h.inspect]
end