Class: Microformats::AbsoluteUri
- Inherits:
-
Object
- Object
- Microformats::AbsoluteUri
- Defined in:
- lib/microformats/absolute_uri.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#relative ⇒ Object
Returns the value of attribute relative.
Instance Method Summary collapse
- #absolutize ⇒ Object
-
#initialize(relative, base: nil) ⇒ AbsoluteUri
constructor
A new instance of AbsoluteUri.
Constructor Details
#initialize(relative, base: nil) ⇒ AbsoluteUri
Returns a new instance of AbsoluteUri.
5 6 7 8 9 10 |
# File 'lib/microformats/absolute_uri.rb', line 5 def initialize(relative, base: nil) @base = base @relative = relative @base = base.strip unless base.nil? @relative = relative.strip unless relative.nil? end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
3 4 5 |
# File 'lib/microformats/absolute_uri.rb', line 3 def base @base end |
#relative ⇒ Object
Returns the value of attribute relative.
3 4 5 |
# File 'lib/microformats/absolute_uri.rb', line 3 def relative @relative end |
Instance Method Details
#absolutize ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/microformats/absolute_uri.rb', line 12 def absolutize return relative if base.nil? return base if relative.nil? || relative == '' return relative if relative =~ %r{^https?://} return base + relative if relative =~ /^#/ uri = URI.parse(relative) uri = URI.join(base.to_s, relative.to_s) if base && !uri.absolute? uri.normalize! uri.to_s rescue URI::BadURIError, URI::InvalidURIError relative.to_s end |