Class: SwipeTrigger

Inherits:
Trigger show all
Defined in:
lib/ruby-macrodroid/triggers.rb

Overview

Category: User Input

Instance Attribute Summary

Attributes inherited from Trigger

#constraints

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods inherited from Trigger

#match?

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(obj = nil) ⇒ SwipeTrigger

Returns a new instance of SwipeTrigger.



1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
# File 'lib/ruby-macrodroid/triggers.rb', line 1749

def initialize(obj=nil)
  
  h = if obj.is_a? Hash then
    obj
  elsif obj.is_a? Array
    
    e, macro = obj
    s = e.text('item/description').to_s
    start, motion = s.split(/ - /,2)
    
    {
      swipe_start_area: ['Top Left', 'Top Right'].index(start),
      swipe_motion: %w(Across Diagonal Down).index(motion)
    }
  end 
  
  options = {
    swipe_start_area: 0,
    swipe_motion: 0,
    cleared: true
  }

  super(options.merge h)

end

Instance Method Details

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



1775
1776
1777
1778
1779
1780
1781
1782
# File 'lib/ruby-macrodroid/triggers.rb', line 1775

def to_s(colour: false)
  
  direction = [['Top Left', 'Top Right'][@h[:swipe_start_area]], 
      %w(Across Diagonal Down)[@h[:swipe_motion]]].join(' - ')
  @s = 'Swipe Screen'# + @h.inspect
  @s += "\n" + direction
  super()
end