Class: Microformats2::AbsoluteUri
- Inherits:
-
Object
- Object
- Microformats2::AbsoluteUri
- Defined in:
- lib/microformats2/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(base, relative) ⇒ AbsoluteUri
constructor
A new instance of AbsoluteUri.
Constructor Details
#initialize(base, relative) ⇒ AbsoluteUri
Returns a new instance of AbsoluteUri.
5 6 7 8 |
# File 'lib/microformats2/absolute_uri.rb', line 5 def initialize(base, relative) @base = base @relative = relative end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
3 4 5 |
# File 'lib/microformats2/absolute_uri.rb', line 3 def base @base end |
#relative ⇒ Object
Returns the value of attribute relative.
3 4 5 |
# File 'lib/microformats2/absolute_uri.rb', line 3 def relative @relative end |
Instance Method Details
#absolutize ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/microformats2/absolute_uri.rb', line 10 def absolutize return nil if relative.nil? or relative == "" uri = URI.parse(relative) if base && !uri.absolute? uri = URI.join(base.to_s, relative.to_s) end uri.normalize! uri.to_s rescue URI::BadURIError, URI::InvalidURIError => e relative.to_s end |