Class: Evinrude::NodeInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/evinrude/node_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address:, port:, name:) ⇒ NodeInfo

Returns a new instance of NodeInfo.



5
6
7
# File 'lib/evinrude/node_info.rb', line 5

def initialize(address:, port:, name:)
	@address, @port, @name = address, port, name
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



3
4
5
# File 'lib/evinrude/node_info.rb', line 3

def address
  @address
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/evinrude/node_info.rb', line 3

def name
  @name
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/evinrude/node_info.rb', line 3

def port
  @port
end

Instance Method Details

#[](k) ⇒ Object

It's useful for a NodeInfo to be able to be treated like a hash sometimes.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/evinrude/node_info.rb', line 10

def [](k)
	case k
	when :address
		@address
	when :port
		@port
	when :name
		@name
	else
		raise ArgumentError, "Invalid key #k.inspect}"
	end
end

#eql?(o) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/evinrude/node_info.rb', line 23

def eql?(o)
	# I know hash equality doesn't mean "equality of hashes", but it amuses
	# me nonetheless that that is a good way to implement it.
	[Evinrude::NodeInfo, Hash].include?(o.class) && { address: @address, port: @port, name: @name}.eql?({ address: o[:address], port: o[:port], name: o[:name] })
end

#hashObject



31
32
33
# File 'lib/evinrude/node_info.rb', line 31

def hash
	{ address: @address, port: @port, name: @name }.hash
end