Class: Droonga::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(components = {}) ⇒ Address

Returns a new instance of Address.



39
40
41
42
# File 'lib/droonga/address.rb', line 39

def initialize(components={})
  @node_name  = NodeName.new(components)
  @local_name = components[:local_name]
end

Instance Attribute Details

#local_nameObject (readonly)

Returns the value of attribute local_name.



38
39
40
# File 'lib/droonga/address.rb', line 38

def local_name
  @local_name
end

Class Method Details

.parse(string) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/droonga/address.rb', line 21

def parse(string)
  if /\A(.+):(\d+)\/([^.]+)(?:\.(.+))?\z/ =~ string
    components = {
      :host => $1,
      :port => $2.to_i,
      :tag  => $3,
      :local_name => $4
    }
    new(components)
  else
    format = "${host_name}:${port_number}/${tag}.${local_name}"
    message = "volume address must be <#{format}> format: <#{string}>"
    raise ArgumentError, message
  end
end

Instance Method Details

#==(other) ⇒ Object



70
71
72
73
74
75
# File 'lib/droonga/address.rb', line 70

def ==(other)
  if other.is_a?(String)
    return to_s == other
  end
  other.is_a?(self.class) and to_a == other.to_a
end

#hostObject



44
45
46
# File 'lib/droonga/address.rb', line 44

def host
  @node_name.host
end

#nodeObject



56
57
58
# File 'lib/droonga/address.rb', line 56

def node
  @node_name.node
end

#portObject



48
49
50
# File 'lib/droonga/address.rb', line 48

def port
  @node_name.port
end

#tagObject



52
53
54
# File 'lib/droonga/address.rb', line 52

def tag
  @node_name.tag
end

#to_aObject



66
67
68
# File 'lib/droonga/address.rb', line 66

def to_a
  @node_name.to_a + [@local_name]
end

#to_sObject



60
61
62
63
64
# File 'lib/droonga/address.rb', line 60

def to_s
  string = @node_name.node
  string << ".#{@local_name}" if @local_name
  string
end