Skip to content

Commit

Permalink
Added YARD code examples for the RDF::URI class.
Browse files Browse the repository at this point in the history
  • Loading branch information
artob committed Nov 15, 2010
1 parent f589b87 commit 0378749
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion lib/rdf/model/uri.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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?
Expand All @@ -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?
Expand All @@ -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?
Expand All @@ -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
Expand All @@ -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([:/#]([^:/#]*)$)
Expand Down Expand Up @@ -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?
Expand All @@ -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?
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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#=~
Expand All @@ -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
Expand Down

0 comments on commit 0378749

Please sign in to comment.