Class: DisableMacroAction

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

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) ⇒ DisableMacroAction

Returns a new instance of DisableMacroAction.



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
1933
1934
1935
1936
# File 'lib/ruby-macrodroid/actions.rb', line 1907

def initialize(obj=nil)
  
  h = if obj.is_a? Hash then
  
    obj
    
  elsif obj.is_a? Array
    
    e, macro, h2 = obj
    
    # find the macro guid for the given name
    name = e.text('item/description').to_s
    found = macro.parent.macros.find {|macro| macro.title =~ /#{name}/ }
    
    h3 = if found then     
      {macro_name: found.title, GUID: found.guid}
    else
      {macro_name: name}
    end
    
    h3.merge h2

  end      
  
  # state: 0 = enable, 1 = disable, 2 = toggle
  
  options = {macro_name: "Change brightness", state: 1, GUID: nil}
  super(options.merge h)
  
end

Instance Method Details

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



1938
1939
1940
1941
1942
1943
1944
1945
# File 'lib/ruby-macrodroid/actions.rb', line 1938

def to_s(colour: false, indent: 0)
  
  state = %w(Enable Disable Toggle)[@h[:state]]
  @s = state + ' macro'# + @h.inspect
  @s += "\n" + @h[:macro_name]
  super()
  
end