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.



910
911
912
913
914
915
916
917
918
919
920
921
922
923
# File 'lib/ruby-macrodroid.rb', line 910

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.



908
909
910
# File 'lib/ruby-macrodroid.rb', line 908

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



907
908
909
# File 'lib/ruby-macrodroid.rb', line 907

def type
  @type
end

Instance Method Details

#to_hObject



925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
# File 'lib/ruby-macrodroid.rb', line 925

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



943
944
945
# File 'lib/ruby-macrodroid.rb', line 943

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