Class: Pubid::Csa::Identifiers::Combined

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/pubid/csa/identifiers/combined.rb

Overview

CombinedIdentifier represents CSA identifiers combined with “/” separator Examples:

CSA A23.1:24/CSA A23.2:24
CSA N285.0:23/CSA N285.6 SERIES:23
CSA A123.1-05/A123.5-05 (R2015)
CSA B44:19/B44.1:19/B44.2:19 (triple combined)

Instance Method Summary collapse

Instance Method Details

#to_sObject



26
27
28
29
30
31
32
33
34
35
36
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
# File 'lib/pubid/csa/identifiers/combined.rb', line 26

def to_s
  # For comma separator, render both parts with full prefix
  # For slash separator, second/third parts without prefix
  if separator == ", "
    # Comma: Both with full CSA prefix
    parts = [first.to_s, second.to_s]
    parts << third.to_s if third
  else
    # Slash: Second and third without CSA prefix (continuation)
    parts = [first.to_s]
    parts << render_continuation(second)
    parts << render_continuation(third) if third
  end

  result = parts.join(separator || "/")

  # Reaffirmation - preserve original format and determine spacing
  if reaffirmation
    # For combined identifiers, check year format from first identifier
    # to determine spacing
    year_was_2digit = first.class.attributes.key?(:original_year_4digit) && !first.original_year_4digit

    # Check if reaffirmation was originally 4-digit
    # Note: We need to track this at the Combined level, but for now
    # assume 4-digit if the value is 4 digits and starts with 19/20
    reaffirmation_was_4digit = reaffirmation.to_s.length == 4 &&
      reaffirmation.to_s.start_with?("19", "20")

    # Determine spacing based on original formats
    # Space needed if year is 2-digit and reaffirmation is 4-digit
    result += if year_was_2digit && reaffirmation_was_4digit
                " (R#{reaffirmation})"
              else
                "(R#{reaffirmation})"
              end
  end

  result += package if package
  result
end