Class: Pubid::Ieee::Identifier

Inherits:
Pubid::Identifier show all
Defined in:
lib/pubid/ieee/identifiers/base.rb

Overview

Base class for all IEEE identifiers. Canonical name Pubid::Ieee::Identifier (Identifiers::Base is a back-compat alias). IEEE builds its identifiers as instances of this class directly.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pubid::Identifier

#base_identifier, #eql?, #exclude, from_hash, #hash, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, polymorphic_type_map, #render, #resolve_urn_generator, #root, #to_hash, #to_mr_string, #to_s, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year

Constructor Details

#initialize(**args) ⇒ Identifier

Returns a new instance of Identifier.



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
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/pubid/ieee/identifiers/base.rb', line 59

def initialize(**args)
  super()

  # Handle typed_stage if provided
  if args[:typed_stage]
    self.typed_stage = args[:typed_stage]
  end

  # Handle code as component object
  if args[:code].is_a?(String)
    self.code_obj = Components::Code.parse(args[:code])
    self.code = args[:code]
  elsif args[:code]
    self.code_obj = args[:code]
    self.code = args[:code].to_s
  end

  # Handle draft as component object
  if args[:draft_obj]
    self.draft_obj = args[:draft_obj]
    self.draft = args[:draft_obj].to_s
  elsif args[:draft].is_a?(String)
    self.draft_obj = Components::Draft.parse(args[:draft])
    self.draft = draft_obj.to_s
  elsif args[:draft]
    self.draft_obj = args[:draft]
    self.draft = args[:draft].to_s
  end

  # Set other attributes
  attrs = self.class.attributes
  args.each do |key, value|
    next if %i[code draft draft_obj typed_stage].include?(key)

    setter = :"#{key}="
    public_send(setter, value) if attrs.key?(key)
  end
end

Instance Attribute Details

#code_objObject

Lazily rebuild the parsed component objects from the underlying string attributes. After from_hash, lutaml restores the :code/:draft strings (@code/@draft) but not these objects; the renderer reads code_obj/ draft_obj directly, so rebuild on demand to render a deserialized identifier identically to the parsed one. On the parse path code_obj/ draft_obj are already set, so the ||= returns them unchanged.



57
58
59
# File 'lib/pubid/ieee/identifiers/base.rb', line 57

def code_obj
  @code_obj
end

#draft_objObject

Store actual component objects



57
58
59
# File 'lib/pubid/ieee/identifiers/base.rb', line 57

def draft_obj
  @draft_obj
end

Class Method Details

.parse(input) ⇒ Object

Parse IEEE identifier string.

PreParser owns all regex/dispatch logic; this method is a thin orchestrator that consumes a PreParser::Result and routes to the correct builder.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/pubid/ieee/identifiers/base.rb', line 135

def self.parse(input)
  if input.length > Pubid::MAX_INPUT_LENGTH
    raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
  end

  result = PreParser.preprocess(input)

  case result.dispatch
  when :aiee_simple
    return Aiee::Identifier.parse(result.input)
  when :iec_ieee_copublished
    return parse_single(result.input)
  when :dual_semicolon
    return build_dual(result.parts)
  when :dual_reaffirmed
    return build_reaffirmed(result)
  when :dual_ire
    return build_dual_with_reaffirmed(result)
  when :dual_space_separated
    return build_dual(result.parts)
  when :dual_and
    return build_dual(result.parts)
  when :dual_ampersand
    return build_dual(result.parts)
  when :aiee_asa_adoption
    return build_aiee_asa_adoption(result.parts)
  when :adopted
    return build_adopted(result.parts)
  else
    parse_single(result.input)
  end
rescue Parslet::ParseFailed
  parse_single(input)
end

.parse_single(input) ⇒ Object

Parse a single IEEE identifier



239
240
241
242
243
244
245
246
247
# File 'lib/pubid/ieee/identifiers/base.rb', line 239

def self.parse_single(input)
  # Apply legacy update_codes normalization first, before Parser's extensive preprocessing
  normalized = Core::UpdateCodes.apply(input, :ieee)
  parsed = Parser.parse(normalized) # Use class method for preprocessing
  builder = Builder.new(Identifier)
  # Pass the original input string to builder for context
  builder.original_input = input
  builder.build(parsed)
end

Instance Method Details

#codeObject

Override accessors to return component objects.



99
100
101
# File 'lib/pubid/ieee/identifiers/base.rb', line 99

def code
  code_obj
end

#draftObject



103
104
105
# File 'lib/pubid/ieee/identifiers/base.rb', line 103

def draft
  draft_obj
end

#draft_monthObject

Expose numeric month from draft if available



124
125
126
127
128
# File 'lib/pubid/ieee/identifiers/base.rb', line 124

def draft_month
  return nil unless draft_obj.is_a?(Components::Draft)

  draft_obj.numeric_month
end

#publisherString

Generate URN for this identifier

Returns:

  • (String)

    URN representation



17
# File 'lib/pubid/ieee/identifiers/base.rb', line 17

attribute :publisher, :string, default: -> { "IEEE" }