Class: MQTTPipe::Types::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/mqtt_pipe/types/color.rb

Constant Summary collapse

PACKER_CODE =
0xC9

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, g, b) ⇒ Color

Returns a new instance of Color.



8
9
10
# File 'lib/mqtt_pipe/types/color.rb', line 8

def initialize r, g, b
  @r, @g, @b = r, g, b
end

Instance Attribute Details

#bObject (readonly)

Returns the value of attribute b.



6
7
8
# File 'lib/mqtt_pipe/types/color.rb', line 6

def b
  @b
end

#gObject (readonly)

Returns the value of attribute g.



6
7
8
# File 'lib/mqtt_pipe/types/color.rb', line 6

def g
  @g
end

#rObject (readonly)

Returns the value of attribute r.



6
7
8
# File 'lib/mqtt_pipe/types/color.rb', line 6

def r
  @r
end

Class Method Details

.from_packed(_, raw) ⇒ Object



18
19
20
21
22
23
# File 'lib/mqtt_pipe/types/color.rb', line 18

def from_packed _, raw
  color = 3.times.map do
    Packer.read_packed_bytes(1, from: raw, as: 'C')
  end
  new *color
end

Instance Method Details

#to_packedObject



12
13
14
# File 'lib/mqtt_pipe/types/color.rb', line 12

def to_packed
  [PACKER_CODE, r, g, b].pack 'C4'
end