Class: Dashed::Button

Inherits:
Object
  • Object
show all
Defined in:
lib/dashed/button.rb

Constant Summary collapse

TIMEOUT =
45
SNAPLENGTH =
65535

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mac_address, interface, timeout = TIMEOUT) ⇒ Button

Returns a new instance of Button.



13
14
15
16
17
18
# File 'lib/dashed/button.rb', line 13

def initialize(mac_address, interface, timeout = TIMEOUT)
  @mac_address = mac_address
  @interface = interface
  @timeout = timeout
  @last_press = nil
end

Instance Attribute Details

#last_pressObject (readonly)

Returns the value of attribute last_press.



11
12
13
# File 'lib/dashed/button.rb', line 11

def last_press
  @last_press
end

#mac_addressObject (readonly)

Returns the value of attribute mac_address.



11
12
13
# File 'lib/dashed/button.rb', line 11

def mac_address
  @mac_address
end

#timeoutObject

Returns the value of attribute timeout.



10
11
12
# File 'lib/dashed/button.rb', line 10

def timeout
  @timeout
end

Instance Method Details

#on_pressObject



20
21
22
23
24
25
26
27
28
# File 'lib/dashed/button.rb', line 20

def on_press
  capture.each_packet do |raw_packet|
    packet = Packet.new(raw_packet)
    if packet.host_mac_address == mac_address && !duplicate_arp?
      @last_press = Time.now
      yield if block_given?
    end
  end
end