Skip to content

Commit

Permalink
Make Droonga::Address subclass of Droonga::NodeName
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Mar 25, 2015
1 parent f3df489 commit 48e28ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
24 changes: 4 additions & 20 deletions lib/droonga/address.rb
Expand Up @@ -16,7 +16,7 @@
require "droonga/node_name"

module Droonga
class Address
class Address < NodeName
class << self
def parse(string)
if /\A(.+):(\d+)\/([^.]+)(?:\.(.+))?\z/ =~ string
Expand All @@ -37,38 +37,22 @@ def parse(string)

attr_reader :name
def initialize(components={})
@node = NodeName.new(components)
super
@name = components[:name]
end

def host
@node.host
end

def port
@node.port
end

def tag
@node.tag
end

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

def to_a
@node.to_a + [@name]
super + [@name]
end

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

def node
@node.to_s
end
end
end
4 changes: 4 additions & 0 deletions lib/droonga/node_name.rb
Expand Up @@ -58,6 +58,10 @@ def initialize(components={})
end

def to_s
node
end

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

Expand Down

0 comments on commit 48e28ad

Please sign in to comment.