Class: Nerpin::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/nerpin/controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(destination, nrpn_class) ⇒ Controller

Returns a new instance of Controller.



3
4
5
6
# File 'lib/nerpin/controller.rb', line 3

def initialize(destination, nrpn_class)
  @destination = destination
  @nrpn_class  = nrpn_class
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)



31
32
33
34
35
36
37
# File 'lib/nerpin/controller.rb', line 31

def method_missing(name, *args)
  if nrpn = @nrpn_class.find_by_key(name)
    puts(nrpn.id, nrpn.value(args.first))
  else
    super
  end
end

Instance Method Details

#nrpnsObject



21
22
23
# File 'lib/nerpin/controller.rb', line 21

def nrpns
  @nrpn_class.instance_variable_get('@nrpns')
end

#puts(id, value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/nerpin/controller.rb', line 8

def puts(id, value)
  mutex.synchronize do
    [
      [0x63, (id >> 7) & 0b1111111],
      [0x62, id        & 0b1111111],
      [0x06, value[:v0x06]],
      [0x26, value[:v0x26]]
    ].each do |message|
      @destination.puts(0b10110000, message[0], message[1])
    end
  end
end