Class: Archipelago::Disco::ServiceDescription
- Inherits:
-
Object
- Object
- Archipelago::Disco::ServiceDescription
- Extended by:
- Forwardable
- Defined in:
- lib/archipelago/disco.rb
Overview
A Hash-like description of a service.
Constant Summary collapse
- IGNORABLE_ATTRIBUTES =
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#eql?(o) ⇒ Boolean
(also: #==)
Returns whether our @attributes are equal to that of
o
. -
#hash ⇒ Object
To make it Hash and Set friendly.
-
#initialize(hash = {}) ⇒ ServiceDescription
constructor
Initialize this service description with a hash that describes its attributes.
-
#matches?(match) ⇒ Boolean
Returns whether this ServiceDescription matches the given
match
.
Constructor Details
#initialize(hash = {}) ⇒ ServiceDescription
Initialize this service description with a hash that describes its attributes.
311 312 313 |
# File 'lib/archipelago/disco.rb', line 311 def initialize(hash = {}) @attributes = hash end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
305 306 307 |
# File 'lib/archipelago/disco.rb', line 305 def attributes @attributes end |
Instance Method Details
#eql?(o) ⇒ Boolean Also known as: ==
Returns whether our @attributes are equal to that of o
.
325 326 327 |
# File 'lib/archipelago/disco.rb', line 325 def eql?(o) ServiceDescription === o && @attributes == o.attributes end |
#hash ⇒ Object
To make it Hash and Set friendly.
317 318 319 320 321 |
# File 'lib/archipelago/disco.rb', line 317 def hash @attributes.inject(0) do |sum, pair| sum + pair.first.hash + pair.last.hash end end |
#matches?(match) ⇒ Boolean
Returns whether this ServiceDescription matches the given match
.
332 333 334 335 336 337 338 339 |
# File 'lib/archipelago/disco.rb', line 332 def matches?(match) match.each do |key, value| unless IGNORABLE_ATTRIBUTES.include?(key) return false unless @attributes.include?(key) && (value.nil? || @attributes[key] == value) end end true end |