diff --git a/lib/rdf/model/uri.rb b/lib/rdf/model/uri.rb index b7cbbec5..46afa535 100644 --- a/lib/rdf/model/uri.rb +++ b/lib/rdf/model/uri.rb @@ -106,16 +106,22 @@ def uri? ## # Returns `true` if this URI is a URN. # + # @example + # RDF::URI('http://example.org/').urn? #=> false + # # @return [Boolean] `true` or `false` # @see http://en.wikipedia.org/wiki/Uniform_Resource_Name # @since 0.2.0 def urn? - to_s.index('urn:') == 0 + self.start_with?('urn:') end ## # Returns `true` if this URI is a URL. # + # @example + # RDF::URI('http://example.org/').url? #=> true + # # @return [Boolean] `true` or `false` # @see http://en.wikipedia.org/wiki/Uniform_Resource_Locator # @since 0.2.0 @@ -126,7 +132,11 @@ def url? ## # Returns the string length of this URI. # + # @example + # RDF::URI('http://example.org/').length #=> 19 + # # @return [Integer] + # @since 0.3.0 def length to_s.length end @@ -283,6 +293,10 @@ def +(other) ## # Returns `true` if this URI's path component is equal to `/`. # + # @example + # RDF::URI('http://example.org/').root? #=> true + # RDF::URI('http://example.org/path/').root? #=> false + # # @return [Boolean] `true` or `false` def root? self.path == '/' || self.path.empty? @@ -291,6 +305,10 @@ def root? ## # Returns a copy of this URI with the path component set to `/`. # + # @example + # RDF::URI('http://example.org/').root #=> RDF::URI('http://example.org/') + # RDF::URI('http://example.org/path/').root #=> RDF::URI('http://example.org/') + # # @return [RDF::URI] def root if root? @@ -305,6 +323,10 @@ def root ## # Returns `true` if this URI's path component isn't equal to `/`. # + # @example + # RDF::URI('http://example.org/').has_parent? #=> false + # RDF::URI('http://example.org/path/').has_parent? #=> true + # # @return [Boolean] `true` or `false` def has_parent? !root? @@ -314,6 +336,10 @@ def has_parent? # Returns a copy of this URI with the path component ascended to the # parent directory, if any. # + # @example + # RDF::URI('http://example.org/').parent #=> nil + # RDF::URI('http://example.org/path/').parent #=> RDF::URI('http://example.org/') + # # @return [RDF::URI] def parent case @@ -332,6 +358,11 @@ def parent ## # Returns a qualified name (QName) for this URI, if possible. # + # @example + # RDF::URI('http://purl.org/dc/terms/').qname #=> [:dc, nil] + # RDF::URI('http://purl.org/dc/terms/title').qname #=> [:dc, :title] + # RDF::DC.title.qname #=> [:dc, :title] + # # @return [Array(Symbol, Symbol)] or `nil` if no QName found def qname if self.to_s =~ %r([:/#]([^:/#]*)$) @@ -372,6 +403,10 @@ def freeze ## # Returns `true` if this URI starts with the given `string`. # + # @example + # RDF::URI('http://example.org/').start_with?('http') #=> true + # RDF::URI('http://example.org/').start_with?('ftp') #=> false + # # @param [String, #to_s] string # @return [Boolean] `true` or `false` # @see String#start_with? @@ -384,6 +419,10 @@ def start_with?(string) ## # Returns `true` if this URI ends with the given `string`. # + # @example + # RDF::URI('http://example.org/').end_with?('/') #=> true + # RDF::URI('http://example.org/').end_with?('#') #=> false + # # @param [String, #to_s] string # @return [Boolean] `true` or `false` # @see String#end_with? @@ -396,6 +435,11 @@ def end_with?(string) ## # Checks whether this URI is equal to `other`. # + # @example + # RDF::URI('http://t.co/').eql?(RDF::URI('http://t.co/')) #=> true + # RDF::URI('http://t.co/').eql?('http://t.co/') #=> false + # RDF::URI('http://purl.org/dc/terms/').eql?(RDF::DC) #=> false + # # @param [RDF::URI] other # @return [Boolean] `true` or `false` def eql?(other) @@ -405,6 +449,11 @@ def eql?(other) ## # Checks whether this URI is equal to `other`. # + # @example + # RDF::URI('http://t.co/') == RDF::URI('http://t.co/') #=> true + # RDF::URI('http://t.co/') == 'http://t.co/' #=> true + # RDF::URI('http://purl.org/dc/terms/') == RDF::DC #=> true + # # @param [Object] other # @return [Boolean] `true` or `false` def ==(other) @@ -418,6 +467,13 @@ def ==(other) ## # Checks for case equality to the given `other` object. # + # @example + # RDF::URI('http://example.org/') === /example/ #=> true + # RDF::URI('http://example.org/') === /foobar/ #=> false + # RDF::URI('http://t.co/') === RDF::URI('http://t.co/') #=> true + # RDF::URI('http://t.co/') === 'http://t.co/' #=> true + # RDF::URI('http://purl.org/dc/terms/') === RDF::DC #=> true + # # @param [Object] other # @return [Boolean] `true` or `false` # @since 0.3.0 @@ -431,6 +487,10 @@ def ===(other) ## # Performs a pattern match using the given regular expression. # + # @example + # RDF::URI('http://example.org/') =~ /example/ #=> 7 + # RDF::URI('http://example.org/') =~ /foobar/ #=> nil + # # @param [Regexp] pattern # @return [Integer] the position the match starts # @see String#=~ @@ -453,6 +513,9 @@ def to_uri ## # Returns the string representation of this URI. # + # @example + # RDF::URI('http://example.org/').to_str #=> 'http://example.org/' + # # @return [String] def to_str @uri.to_s