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 MacroObject

#to_h

Constructor Details

#initialize(obj = nil) ⇒ SwipeTrigger

Returns a new instance of SwipeTrigger.



1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
# File 'lib/ruby-macrodroid/triggers.rb', line 1766

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

#match?(detail = {}, model = nil) ⇒ Boolean

Returns:

  • (Boolean)


1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
# File 'lib/ruby-macrodroid/triggers.rb', line 1792

def match?(detail={}, model=nil)
  
  puts 'detail : ' + detail.inspect
      
  return false if detail.empty?
 
  detail[:swipe_start_area] = detail[:start]
  detail[:swipe_motion] = detail[:motion]
  return unless detail[:swipe_start_area] and detail[:swipe_motion]
  
  @h[:swipe_start_area] == detail[:swipe_start_area].to_i and \
     @h[:swipe_motion] == detail[:swipe_motion].to_i

end

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



1807
1808
1809
1810
1811
1812
1813
1814
# File 'lib/ruby-macrodroid/triggers.rb', line 1807

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