Module: Coradoc::Reference::Address::Url
- Defined in:
- lib/coradoc/reference/address/url.rb
Overview
Absolute URL — anything with a recognized URL scheme prefix. Fragment is the optional "#..." suffix.
Constant Summary collapse
- URL_PATTERN =
%r{\A([a-z][a-z0-9+\-.]*)://([^#]+)(?:#(.*))?\z}i
Class Method Summary collapse
Class Method Details
.matches?(raw) ⇒ Boolean
17 18 19 20 21 |
# File 'lib/coradoc/reference/address/url.rb', line 17 def matches?(raw) return false if raw.nil? || raw.empty? URL_PATTERN.match?(raw.to_s) end |
.parse(raw) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/coradoc/reference/address/url.rb', line 23 def parse(raw) match = URL_PATTERN.match(raw.to_s) raise Address::ParseError, "Invalid URL: #{raw.inspect}" unless match target = "#{match[1]}://#{match[2]}" fragment = match[3] Address.new(scheme: 'url', target: target, fragment: fragment) end |
.scheme_name ⇒ Object
13 14 15 |
# File 'lib/coradoc/reference/address/url.rb', line 13 def scheme_name :url end |
.serialize(address) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/coradoc/reference/address/url.rb', line 32 def serialize(address) base = address.target.to_s return base unless address.fragment && !address.fragment.empty? "#{base}##{address.fragment}" end |