Class: SetVariableAction

Inherits:
MacroDroidAction show all
Defined in:
lib/ruby-macrodroid/actions.rb

Overview

MacroDroid Specific

Instance Attribute Summary

Attributes inherited from Action

#constraints

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods inherited from Action

#invoke

Methods included from ObjectX

#action_to_object, #object_create, #varify

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(obj = nil) ⇒ SetVariableAction

Returns a new instance of SetVariableAction.



1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
# File 'lib/ruby-macrodroid/actions.rb', line 1855

def initialize(obj=nil)
  
  h = if obj.is_a? Hash then
    obj
  elsif obj.is_a? Array
    e, macro = obj
    node = e.element('item/*')
    #puts ("node.name: %s node.value: %s" % [node.name, node.value]).debug
    r = macro.set_var node.name, node.value.to_s
    puts ('r: ' + r.inspect).debug if $debug
    r
    if r[:type] == 2 then
      { variable: {name: r[:name], type: r[:type]}, new_string_value: r[:string_value]
        }
    end
  end    
  
  options = {
    :user_prompt=>true, 
    :user_prompt_message=>"Please enter a word to see it reversed", 
    :user_prompt_show_cancel=>true, 
    :user_prompt_stop_after_cancel=>true, 
    :user_prompt_title=>"Word reverse",
    :name => 'word',
    :false_label=>"False", :int_expression=>false, :int_random=>false, 
    :int_random_max=>0, :int_random_min=>0, :int_value_decrement=>false, 
    :int_value_increment=>false, :new_boolean_value=>false, 
    :new_double_value=>0.0, :new_int_value=>0, 
    :new_string_value=>"[battery]", :true_label=>"True", 
    :user_prompt=>false, :user_prompt_show_cancel=>true, 
    :user_prompt_stop_after_cancel=>true, 
    :variable=>{
                :exclude_from_log=>false, :is_local=>true, 
                :boolean_value=>false, :decimal_value=>0.0, 
                :int_value=>0, :name=>"foo", :string_value=>"52", :type=>2
    }
  }
  super(options.merge h)
  
end

Instance Method Details

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



1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
# File 'lib/ruby-macrodroid/actions.rb', line 1896

def to_s(colour: false, indent: 0)
  
  input = if @h[:user_prompt] then
    '[User Prompt]'
  elsif @h[:expression]
    @h[:expression]
  elsif @h[:int_value_increment]
    '(+1)'      
  elsif @h[:int_value_decrement]
    '(-1)'
  elsif @h[:int_random]
    "Random %d -> %d" % [@h[:int_random_min], @h[:int_random_max]]
  else

=begin      
      sym = case @h[:variable][:type]
      when 0 # boolean
        :new_boolean_value
      when 1 # integer
        :new_int_value
      when 2 # string
        :new_string_value
      when 3 # decimal
        :new_double_value
      end
      
      @h[sym].to_s
=end        

      a = i(new_boolean_value new_int_value new_string_value new_double_value)
      @h[a[@h[:variable][:type]]].to_s

  end
  
  @s = 'Set Variable' + ("\n%s: " % @h[:variable][:name]) + input #+ @h.inspect
  super()
  
end