class MacroDroidVariableConstraint

Category: MacroDroid Specific

Public Class Methods

new(h={}) click to toggle source
Calls superclass method Constraint::new
# 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

Public Instance Methods

to_s(colour: false, indent: 0) click to toggle source
Calls superclass method MacroObject#to_s
# 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
Also aliased as: to_summary
to_summary(colour: false, indent: 0)
Alias for: to_s