Class: Player::DevAddr

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/ruby-player/dev_addr.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addr = {}) ⇒ DevAddr

Returns a new instance of DevAddr.



21
22
23
24
25
26
# File 'lib/ruby-player/dev_addr.rb', line 21

def initialize(addr = {})
  @host = addr[:host].to_i
  @robot = addr[:robot].to_i
  @interface = addr[:interface].to_i
  @index = addr[:index].to_i
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



19
20
21
# File 'lib/ruby-player/dev_addr.rb', line 19

def host
  @host
end

#indexObject (readonly)

Returns the value of attribute index.



19
20
21
# File 'lib/ruby-player/dev_addr.rb', line 19

def index
  @index
end

#interfaceObject (readonly)

Returns the value of attribute interface.



19
20
21
# File 'lib/ruby-player/dev_addr.rb', line 19

def interface
  @interface
end

#robotObject (readonly)

Returns the value of attribute robot.



19
20
21
# File 'lib/ruby-player/dev_addr.rb', line 19

def robot
  @robot
end

Class Method Details

.decode(str) ⇒ Object



28
29
30
31
# File 'lib/ruby-player/dev_addr.rb', line 28

def DevAddr.decode(str)
  ary = str.unpack("NNNN")
  DevAddr.new(host: ary[0], robot: ary[1], interface: ary[2], index: ary[3])
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
# File 'lib/ruby-player/dev_addr.rb', line 41

def ==(other)
  @host == other.host and @robot == other.robot and @interface == other.interface and @index == other.index
end

#encodeObject



33
34
35
# File 'lib/ruby-player/dev_addr.rb', line 33

def encode
  [@host, @robot, @interface, @index].pack("NNNN")
end

#interface_nameObject



37
38
39
# File 'lib/ruby-player/dev_addr.rb', line 37

def interface_name
  @interface_name ||= search_interface_name(@interface)
end

#to_aObject



49
50
51
# File 'lib/ruby-player/dev_addr.rb', line 49

def to_a
  [@host, @robot, @interface, @index]
end

#to_sObject



45
46
47
# File 'lib/ruby-player/dev_addr.rb', line 45

def to_s
  "device addr [#@host:#@robot] #{interface_name}:#@index"
end