Module: Coradoc::Reference::Address::Anchor
- Defined in:
- lib/coradoc/reference/address/anchor.rb
Overview
In-document anchor — the most common navigation target. Matches raw strings starting with "#" plus bareword names that don't look like document IDs or external URLs.
"#intro" => anchor target "intro"
"intro" => anchor target "intro"
"footnote-1" => anchor target "footnote-1"
Class Method Summary collapse
- .matches?(raw) ⇒ Boolean
- .new_address(target:) ⇒ Object
- .parse(raw) ⇒ Object
- .scheme_name ⇒ Object
- .serialize(address) ⇒ Object
Class Method Details
.matches?(raw) ⇒ Boolean
20 21 22 23 24 25 26 27 28 |
# File 'lib/coradoc/reference/address/anchor.rb', line 20 def matches?(raw) return false if raw.nil? || raw.empty? stripped = raw.to_s return false if stripped == '#' return true if stripped.start_with?('#') stripped.match?(/\A[\w.\-]+\z/) end |
.new_address(target:) ⇒ Object
42 43 44 |
# File 'lib/coradoc/reference/address/anchor.rb', line 42 def new_address(target:) Address.new(scheme: 'anchor', target: target) end |
.parse(raw) ⇒ Object
30 31 32 33 |
# File 'lib/coradoc/reference/address/anchor.rb', line 30 def parse(raw) target = raw.to_s.delete_prefix('#') new_address(target: target) end |
.scheme_name ⇒ Object
16 17 18 |
# File 'lib/coradoc/reference/address/anchor.rb', line 16 def scheme_name :anchor end |
.serialize(address) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/coradoc/reference/address/anchor.rb', line 35 def serialize(address) target = address.target return '' if target.nil? || target.empty? "##{target}" end |