Class: Archipelago::Disco::ServiceDescription

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/archipelago/disco.rb

Overview

A Hash-like description of a service.

Direct Known Subclasses

Query, Record

Constant Summary collapse

IGNORABLE_ATTRIBUTES =

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject (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.

Returns:

  • (Boolean)


325
326
327
# File 'lib/archipelago/disco.rb', line 325

def eql?(o)
  ServiceDescription === o && @attributes == o.attributes
end

#hashObject

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.

Returns:

  • (Boolean)


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