Class: Droonga::Address

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

Constant Summary collapse

DEFAULT_HOST =
Socket.gethostname
DEFAULT_PORT =
10031
DEFAULT_TAG =
"droonga"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(components = {}) ⇒ Address

Returns a new instance of Address.



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

def initialize(components={})
  @host = components[:host] || DEFAULT_HOST
  @port = components[:port] || DEFAULT_PORT
  @tag  = components[:tag]  || DEFAULT_TAG
  @name = components[:name]
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#nameObject (readonly)

Returns the value of attribute name.



46
47
48
# File 'lib/droonga/address.rb', line 46

def name
  @name
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#tagObject (readonly)

Returns the value of attribute tag.



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

def tag
  @tag
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,
      :name => $4
    }
    new(components)
  else
    format = "${host_name}:${port_number}/${tag}.${name}"
    message = "volume address must be <#{format}> format: <#{string}>"
    raise ArgumentError, message
  end
end

Instance Method Details

#==(other) ⇒ Object



64
65
66
# File 'lib/droonga/address.rb', line 64

def ==(other)
  other.is_a?(self.class) and to_a == other.to_a
end

#nodeObject



68
69
70
# File 'lib/droonga/address.rb', line 68

def node
  "#{@host}:#{@port}/#{@tag}"
end

#to_aObject



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

def to_a
  [@host, @port, @tag, @name]
end

#to_sObject



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

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