Module: Coradoc::Reference::Address::ScopedPath
- Defined in:
- lib/coradoc/reference/address/scoped_path.rb
Overview
Scoped path — a path within a collection's namespace. The scope identifies the collection (e.g. "ELF"); the target is the path inside it ("5005:1"); the fragment is locality within that doc.
"ELF:5005:1#sec-3" => scope "ELF", target "5005:1", fragment "sec-3"
Constant Summary collapse
- SCOPED_PATTERN =
/\A([A-Z][A-Z0-9_\-]*):([\d:]+)(?:#(.*))?\z/
Class Method Summary collapse
Class Method Details
.matches?(raw) ⇒ Boolean
20 21 22 23 24 |
# File 'lib/coradoc/reference/address/scoped_path.rb', line 20 def matches?(raw) return false if raw.nil? || raw.empty? SCOPED_PATTERN.match?(raw.to_s) end |
.parse(raw) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/coradoc/reference/address/scoped_path.rb', line 26 def parse(raw) match = SCOPED_PATTERN.match(raw.to_s) raise Address::ParseError, "Invalid scoped path: #{raw.inspect}" unless match Address.new( scheme: 'scoped_path', scope: match[1], target: match[2], fragment: match[3] ) end |
.scheme_name ⇒ Object
16 17 18 |
# File 'lib/coradoc/reference/address/scoped_path.rb', line 16 def scheme_name :scoped_path end |
.serialize(address) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/coradoc/reference/address/scoped_path.rb', line 38 def serialize(address) base = "#{address.scope}:#{address.target}" return base unless address.fragment && !address.fragment.empty? "#{base}##{address.fragment}" end |