Class: MacroDroidVariableConstraint

Inherits:
Constraint show all
Defined in:
lib/ruby-macrodroid/constraints.rb

Overview

Category: MacroDroid Specific

Instance Attribute Summary

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods inherited from Constraint

#match?

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(h = {}) ⇒ MacroDroidVariableConstraint

Returns a new instance of MacroDroidVariableConstraint.



795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
# File 'lib/ruby-macrodroid/constraints.rb', line 795

def initialize(h={})

  if h[:loperand] then
    h[:variable] = {}
    h[:variable][:name] = h[:loperand]
    h[:variable][:type] = 2
    
    if h[:roperand] =~ /true|false/i then
      
      val = h[:roperand].downcase == 'true'
      h[:boolean_value] = val
      h[:variable][:type] = 0
      h[:variable][:boolean_value] = val
      h[:string_value] = h[:roperand].capitalize
    else
      h[:string_value] = h[:roperand]
    end

  end
      
  options = {
    
    :enable_regex=>false, 
    :boolean_value=>false, 
    :double_value=>0.0, 
    :int_compare_variable=>false, 
    :int_greater_than=>false, 
    :int_less_than=>false, 
    :int_not_equal=>false, 
    :int_value=>1, 
    :string_comparison_type=>0,
    :string_equal=>true, 
    :variable=>{
                :exclude_from_log=>false, 
                :is_local=>true, 
                :boolean_value=>false, 
                :decimal_value=>0.0, 
                :int_value=>2, 
                :name=>"torch", 
                :string_value=>"", 
                :type=>1
               }      

  }

  super(options.merge h)

end

Instance Method Details

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



844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
# File 'lib/ruby-macrodroid/constraints.rb', line 844

def to_s(colour: false, indent: 0)
  
  a = [:int_greater_than, :int_less_than, :int_not_equal, 
            :string_equal].zip(['>','<','!=', '='])
  operator = a.find {|label,_| @h[label]}.last
  
  var = @h[:variable]
  
  type = case var[:type]
  when 0 # boolean
    :boolean_value
  when 1 # integer
    :int_value
  when 2 # string
    :string_value
  when 3 # decimal
    :decimal_Value
  end  
  
  @s = "%s %s %s" % [@h[:variable][:name], operator, @h[type]]
  super()
end