Class: Ace::Support::Items::Atoms::ItemIdFormatter
- Inherits:
-
Object
- Object
- Ace::Support::Items::Atoms::ItemIdFormatter
- Defined in:
- lib/ace/support/items/atoms/item_id_formatter.rb
Overview
Splits and reconstructs 6-char b36ts IDs with type markers.
A raw 6-char b36ts ID “8ppq7w” becomes “8pp.t.q7w” with type marker “t”. Subtasks append a single character: “8pp.t.q7w.a”
Class Method Summary collapse
-
.folder_name(formatted_id, slug) ⇒ String
Build a folder name from formatted ID and slug.
-
.reconstruct(formatted_id) ⇒ String
Reconstruct a raw 6-char b36ts ID from a formatted ID string.
-
.split(raw_b36ts, type_marker:) ⇒ Models::ItemId
Split a 6-char b36ts ID into prefix.marker.suffix format.
-
.split_subtask(raw_b36ts, type_marker:, subtask_char:) ⇒ Models::ItemId
Create an ItemId with a subtask character.
Class Method Details
.folder_name(formatted_id, slug) ⇒ String
Build a folder name from formatted ID and slug
70 71 72 73 74 75 76 |
# File 'lib/ace/support/items/atoms/item_id_formatter.rb', line 70 def self.folder_name(formatted_id, slug) if slug.nil? || slug.empty? formatted_id else "#{formatted_id}-#{slug}" end end |
.reconstruct(formatted_id) ⇒ String
Reconstruct a raw 6-char b36ts ID from a formatted ID string
59 60 61 62 63 64 |
# File 'lib/ace/support/items/atoms/item_id_formatter.rb', line 59 def self.reconstruct(formatted_id) match = formatted_id.match(/^([0-9a-z]{3})\.([a-z])\.([0-9a-z]{3})(?:\.([0-9a-z]))?$/) raise ArgumentError, "Invalid formatted ID: #{formatted_id.inspect}" unless match "#{match[1]}#{match[3]}" end |
.split(raw_b36ts, type_marker:) ⇒ Models::ItemId
Split a 6-char b36ts ID into prefix.marker.suffix format
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ace/support/items/atoms/item_id_formatter.rb', line 27 def self.split(raw_b36ts, type_marker:) raise ArgumentError, "Expected 6-char b36ts ID, got #{raw_b36ts.inspect}" unless raw_b36ts.is_a?(String) && raw_b36ts.length == 6 Models::ItemId.new( raw_b36ts: raw_b36ts, prefix: raw_b36ts[0..2], type_marker: type_marker, suffix: raw_b36ts[3..5], subtask_char: nil ) end |
.split_subtask(raw_b36ts, type_marker:, subtask_char:) ⇒ Models::ItemId
Create an ItemId with a subtask character
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ace/support/items/atoms/item_id_formatter.rb', line 44 def self.split_subtask(raw_b36ts, type_marker:, subtask_char:) item_id = split(raw_b36ts, type_marker: type_marker) Models::ItemId.new( raw_b36ts: item_id.raw_b36ts, prefix: item_id.prefix, type_marker: item_id.type_marker, suffix: item_id.suffix, subtask_char: subtask_char ) end |