Class: JobDispatch::Identity

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/job_dispatch/identity.rb

Overview

Identity encapsulates a ZeroMQ socket identity, which is a string of binary characters, typically containing nulls or non-utf8 compatible characters in ASCII-8BIT encoding.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identity) ⇒ Identity

Returns a new instance of Identity.



13
14
15
# File 'lib/job_dispatch/identity.rb', line 13

def initialize(identity)
  @identity = identity.to_sym
end

Instance Attribute Details

#identityObject (readonly)

Returns the value of attribute identity.



11
12
13
# File 'lib/job_dispatch/identity.rb', line 11

def identity
  @identity
end

Instance Method Details

#<=>(other) ⇒ Object



49
50
51
# File 'lib/job_dispatch/identity.rb', line 49

def <=>(other)
  @identity <=> other.identity
end

#==(other) ⇒ Object



41
42
43
# File 'lib/job_dispatch/identity.rb', line 41

def ==(other)
  @identity == other.identity
end

#as_json(options = {}) ⇒ Object



29
30
31
# File 'lib/job_dispatch/identity.rb', line 29

def as_json(options={})
  to_hex.as_json(options)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/job_dispatch/identity.rb', line 45

def eql?(other)
  self.class == other.class && @identity == other.identity
end

#hashObject



37
38
39
# File 'lib/job_dispatch/identity.rb', line 37

def hash
  @identity.hash
end

#to_hexObject



25
26
27
# File 'lib/job_dispatch/identity.rb', line 25

def to_hex
  @identity.to_s.bytes.map { |x| '%02x' % x }.join
end

#to_sObject



17
18
19
# File 'lib/job_dispatch/identity.rb', line 17

def to_s
  @identity.to_s
end

#to_strObject



21
22
23
# File 'lib/job_dispatch/identity.rb', line 21

def to_str
  @identity.to_str
end

#to_symObject



33
34
35
# File 'lib/job_dispatch/identity.rb', line 33

def to_sym
  @identity
end