Class: Artoo::Drivers::Leapmotion::Gesture

Inherits:
Object
  • Object
show all
Defined in:
lib/artoo/drivers/leapmotion/gesture.rb

Overview

Recognized movement by the user

There is 4 Gesture subclasses :

Circle - A circular movement by a finger.
Swipe - A straight line movement by the hand with fingers extended.
KeyTap -  A downward tapping movement by a finger.
ScreenTap - A forward tapping movement by a finger.

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Gesture

Public: initialize

data - params

Returns nil



58
59
60
61
62
63
64
65
66
67
# File 'lib/artoo/drivers/leapmotion/gesture.rb', line 58

def initialize(data)
  data.each do |key, value|
    instance_variable_set("@#{key}", value)
    self.class.send(
      :define_method,
      key.to_sym,
      lambda { instance_variable_get("@#{key}") }
    )
  end
end

Class Method Details

.list(data) ⇒ Object

Public: Iterates through LeapMotion frame data, extracting all Hand JSON into new Leapmotion::Hand objects.

data - a LeapMotion frame that may or may not contain hand data

Returns an array containing all Hands found in the frame



22
23
24
25
# File 'lib/artoo/drivers/leapmotion/gesture.rb', line 22

def self.list(data)
  return [] unless data["gestures"]
  data["gestures"].map { |gesture| make_gesture gesture }
end

.make_gesture(data) ⇒ Object

Public: Makes a gesture for te leapmotion

data - params

Returns an array



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/artoo/drivers/leapmotion/gesture.rb', line 32

def self.make_gesture(data)
  unless data.has_key? "type"
    raise Error, "gesture type unknown"
  end

  name = data["type"][0].upcase << data["type"][1..-1]

  unless class_exists?(name)
    raise Error, "gesture class `#{self}::#{name}' invalid"
  end

  const_get(name).new(data)
end

Instance Method Details

#start_positionObject

Public: Starts the driver

Returns an nil



49
50
51
# File 'lib/artoo/drivers/leapmotion/gesture.rb', line 49

def start_position
  @startPosition
end