lib/riak/link.rb in ripple-0.6.0 vs lib/riak/link.rb in ripple-0.6.1

- old
+ new

@@ -20,10 +20,12 @@ # @return [String] the URL (relative or absolute) of the related resource attr_accessor :url # @return [String] the relationship ("rel") of the other resource to this one attr_accessor :rel + alias :tag :rel + alias :tag= :rel= # @param [String] header_string the string value of the Link: HTTP header from a Riak response # @return [Array<Link>] an array of Riak::Link structs parsed from the header def self.parse(header_string) header_string.scan(%r{<([^>]+)>\s*;\s*(?:rel|riaktag)=\"([^\"]+)\"}).map do |match| @@ -35,21 +37,29 @@ @url, @rel = url, rel end # @return [String] bucket_name, if the Link url is a known Riak link ("/riak/<bucket>/<key>") def bucket - $1 if url =~ %r{/riak/([^/]+)/?} + URI.unescape($1) if url =~ %r{^/[^/]+/([^/]+)/?} end # @return [String] key, if the Link url is a known Riak link ("/riak/<bucket>/<key>") def key - $1 if url =~ %r{/riak/[^/]+/([^/]+)/?} + URI.unescape($1) if url =~ %r{^/[^/]+/[^/]+/([^/]+)/?} end def inspect; to_s; end def to_s %Q[<#{@url}>; riaktag="#{@rel}"] + end + + def hash + self.to_s.hash + end + + def eql?(other) + self == other end def ==(other) other.is_a?(Link) && url == other.url && rel == other.rel end