Class: Ace::Support::Items::Atoms::ItemIdParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/items/atoms/item_id_parser.rb

Overview

Parses various reference forms into an ItemId model.

Supported formats:

- Full:    "8pp.t.q7w"    → prefix=8pp, marker=t, suffix=q7w
- Short:   "t.q7w"        → prefix=nil, marker=t, suffix=q7w
- Suffix:  "q7w"          → prefix=nil, marker=nil, suffix=q7w
- Subtask: "8pp.t.q7w.a"  → prefix=8pp, marker=t, suffix=q7w, subtask=a
- Raw:     "8ppq7w"       → prefix=8pp, marker=nil, suffix=q7w (6-char raw b36ts)

Constant Summary collapse

FULL_PATTERN =

Full format: prefix.marker.suffix (e.g., “8pp.t.q7w”)

/^([0-9a-z]{3})\.([a-z])\.([0-9a-z]{3})$/
SUBTASK_PATTERN =

Full with subtask: prefix.marker.suffix.subtask (e.g., “8pp.t.q7w.a”)

/^([0-9a-z]{3})\.([a-z])\.([0-9a-z]{3})\.([0-9a-z])$/
SHORT_PATTERN =

Short format: marker.suffix (e.g., “t.q7w”)

/^([a-z])\.([0-9a-z]{3})$/
SUFFIX_PATTERN =

Suffix-only: 3 chars (e.g., “q7w”)

/^[0-9a-z]{3}$/
RAW_PATTERN =

Raw 6-char b36ts (e.g., “8ppq7w”)

/^[0-9a-z]{6}$/

Class Method Summary collapse

Class Method Details

.parse(ref, default_marker: nil) ⇒ ItemId?

Parse a reference string into an ItemId

Parameters:

  • ref (String)

    Reference in any supported format

  • default_marker (String, nil) (defaults to: nil)

    Default type marker for ambiguous refs

Returns:

  • (ItemId, nil)

    Parsed item ID or nil if unparseable



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ace/support/items/atoms/item_id_parser.rb', line 37

def self.parse(ref, default_marker: nil)
  return nil if ref.nil? || ref.empty?

  ref = ref.strip.downcase

  # Try each pattern in order of specificity
  if (match = ref.match(SUBTASK_PATTERN))
    Models::ItemId.new(
      raw_b36ts: "#{match[1]}#{match[3]}",
      prefix: match[1],
      type_marker: match[2],
      suffix: match[3],
      subtask_char: match[4]
    )
  elsif (match = ref.match(FULL_PATTERN))
    Models::ItemId.new(
      raw_b36ts: "#{match[1]}#{match[3]}",
      prefix: match[1],
      type_marker: match[2],
      suffix: match[3],
      subtask_char: nil
    )
  elsif (match = ref.match(SHORT_PATTERN))
    Models::ItemId.new(
      raw_b36ts: nil,
      prefix: nil,
      type_marker: match[1],
      suffix: match[2],
      subtask_char: nil
    )
  elsif ref.match?(SUFFIX_PATTERN)
    Models::ItemId.new(
      raw_b36ts: nil,
      prefix: nil,
      type_marker: default_marker,
      suffix: ref,
      subtask_char: nil
    )
  elsif ref.match?(RAW_PATTERN)
    Models::ItemId.new(
      raw_b36ts: ref,
      prefix: ref[0..2],
      type_marker: default_marker,
      suffix: ref[3..5],
      subtask_char: nil
    )
  end
end