Class: MPS::RefResolver
- Inherits:
-
Object
- Object
- MPS::RefResolver
- Defined in:
- lib/mps/ref_resolver.rb
Overview
Translates between epoch ref-paths (e.g. “20260428.2.1”) and human-readable refs (e.g. “note-1.1”).
Human ref format:
Top-level non-MPS: {type}-{n} where n counts per type across top-level
First-level nested: {parent_human}.{m} where m is the child's sequential index
Deeper nesting: same pattern extended (type-1.2.1, etc.)
@mps containers: mps-{n}
Instance Method Summary collapse
-
#all_epoch_refs ⇒ Object
Returns all mapped epoch refs sorted by document order.
-
#initialize(elements_hash) ⇒ RefResolver
constructor
A new instance of RefResolver.
-
#resolve(ref_str) ⇒ Object
Resolves either form.
-
#to_epoch(human_ref) ⇒ Object
Returns the epoch ref for
human_ref, or nil if not mapped. -
#to_human(epoch_ref) ⇒ Object
Returns the human ref for
epoch_ref, or nil if not mapped.
Constructor Details
#initialize(elements_hash) ⇒ RefResolver
Returns a new instance of RefResolver.
13 14 15 16 17 |
# File 'lib/mps/ref_resolver.rb', line 13 def initialize(elements_hash) @epoch_to_human = {} @human_to_epoch = {} _build_maps(elements_hash) end |
Instance Method Details
#all_epoch_refs ⇒ Object
Returns all mapped epoch refs sorted by document order.
38 39 40 |
# File 'lib/mps/ref_resolver.rb', line 38 def all_epoch_refs @epoch_to_human.keys end |
#resolve(ref_str) ⇒ Object
Resolves either form. Human refs are translated to epoch; epoch refs are returned as-is (validated to exist in the mapping).
31 32 33 34 35 |
# File 'lib/mps/ref_resolver.rb', line 31 def resolve(ref_str) return @human_to_epoch[ref_str] if @human_to_epoch.key?(ref_str) return ref_str if @epoch_to_human.key?(ref_str) nil end |
#to_epoch(human_ref) ⇒ Object
Returns the epoch ref for human_ref, or nil if not mapped.
25 26 27 |
# File 'lib/mps/ref_resolver.rb', line 25 def to_epoch(human_ref) @human_to_epoch[human_ref] end |
#to_human(epoch_ref) ⇒ Object
Returns the human ref for epoch_ref, or nil if not mapped.
20 21 22 |
# File 'lib/mps/ref_resolver.rb', line 20 def to_human(epoch_ref) @epoch_to_human[epoch_ref] end |