Class: Pubid::Ieee::Aiee::Identifier

Inherits:
Identifier show all
Includes:
Identifiers::CodeNumber
Defined in:
lib/pubid/ieee/aiee/identifier.rb

Overview

AIEE identifiers (American Institute of Electrical Engineers: 1884-1963).

Reparented onto Pubid::Ieee::Identifier + the CodeNumber mixin so AIEE shares the flat split-column serialization (number/prefix/parts/ separator), a polymorphic _type, #root, and from_hash routing with every other IEEE type. Previously it descended from bare Lutaml::Model::Serializable and serialized a nested code object with no _type, so Pubid::Ieee::Identifier.from_hash could not route back to this class and dropped the code entirely — every AIEE row failed the relaton index-v2 round-trip gate and had a nil root.number.

The date long-form separator is named date_separator (not separator) to avoid colliding with the CodeNumber code-part separator.

Instance Attribute Summary

Attributes inherited from Identifier

#code_obj, #draft_obj

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Identifiers::CodeNumber

#code_obj, included, #initialize, #rebuild_code_obj_from_split, #sync_split_from_code_obj

Methods inherited from Identifier

additional_identifier_classes, #code, #draft, #draft_month, #exclude, from_hash, #initialize, #mr_number_with_part, #mr_publisher, #mr_type, #mr_year, parse_single, #publisher, #to_hash

Methods inherited from Pubid::Identifier

apply_mappings, #base, #base_document, concrete_class_for, #dated_version_of?, #draft_of?, #drop_supplements, #edition_of?, #eql?, #exclude, from_hash, #has_supplement?, #hash, #includes?, #initialize, #matches?, #mr_all_parts, #mr_edition, #mr_languages, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_subpart, #mr_supplement_suffix, #mr_type, #mr_year, #new_edition_of?, polymorphic_type_map, #related_to?, #render, #resolve_urn_generator, #root, #sibling_of?, #supplement_of?, #to_hash, #to_mr_string, #to_slug, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year

Class Method Details

.parse(input) ⇒ Object

Parse AIEE identifier string



37
38
39
40
# File 'lib/pubid/ieee/aiee/identifier.rb', line 37

def self.parse(input)
  parsed = Parser.new.parse(input)
  Builder.new.build(parsed)
end

.polymorphic_nameObject

A distinct polymorphic name so from_hash routes to AIEE. The derived default (last name segment "Identifier") would be "pubid:ieee:identifier", colliding with the base class.



32
33
34
# File 'lib/pubid/ieee/aiee/identifier.rb', line 32

def self.polymorphic_name
  "pubid:ieee:aiee"
end

Instance Method Details

#to_s(date_format: nil, trademark: false) ⇒ Object



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
85
# File 'lib/pubid/ieee/aiee/identifier.rb', line 42

def to_s(date_format: nil, trademark: false)
  result = [publisher]
  result << type if type
  result << code.to_s if code

  base = result.join(" ")

  # IEEE attaches the mark to the number, before the date suffix
  # ("AIEE No 13™-1930").
  if trademark
    base += Pubid::Ieee.trademark_symbol_for(code_obj&.number,
                                             code_obj&.prefix,
                                             publishers: [publisher])
  end

  # Priority: explicit parameter > original_format > format auto-detect
  format = date_format&.to_s || original_format
  format ||= month || date_separator ? "long" : "short"

  if year
    case format
    when "short", :short
      base += "-#{year}"
    when "long", :long
      sep = date_separator || "," # Default to comma for long form
      base += "#{sep} #{"#{month} " if month}#{year}"
    else
      base += if date_separator
                "#{date_separator} #{"#{month} " if month}#{year}"
              elsif month
                ", #{month} #{year}"
              else
                "-#{year}"
              end
    end
  end

  # The descriptive relationships narrative is deliberately kept out of
  # to_s (an identifier string must stay bounded — it is used as a
  # document number/filename downstream). It stays reachable on
  # `relationships`.

  base
end