Class: Droonga::Address
- Inherits:
-
Object
- Object
- Droonga::Address
- Defined in:
- lib/droonga/address.rb
Constant Summary collapse
- DEFAULT_HOST =
Socket.gethostname
- DEFAULT_PORT =
10031
- DEFAULT_TAG =
"droonga"
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(components = {}) ⇒ Address
constructor
A new instance of Address.
- #node ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
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
#host ⇒ Object (readonly)
Returns the value of attribute host.
43 44 45 |
# File 'lib/droonga/address.rb', line 43 def host @host end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
46 47 48 |
# File 'lib/droonga/address.rb', line 46 def name @name end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
44 45 46 |
# File 'lib/droonga/address.rb', line 44 def port @port end |
#tag ⇒ Object (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}" = "volume address must be <#{format}> format: <#{string}>" raise ArgumentError, 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 |
#node ⇒ Object
68 69 70 |
# File 'lib/droonga/address.rb', line 68 def node "#{@host}:#{@port}/#{@tag}" end |
#to_a ⇒ Object
60 61 62 |
# File 'lib/droonga/address.rb', line 60 def to_a [@host, @port, @tag, @name] end |
#to_s ⇒ Object
54 55 56 57 58 |
# File 'lib/droonga/address.rb', line 54 def to_s string = node string << ".#{@name}" if @name string end |