Class: Pubid::Ieee::Identifiers::Base

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

Overview

Base class for all IEEE identifiers

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pubid::Identifier

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

Constructor Details

#initialize(**args) ⇒ Base

Returns a new instance of Base.



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

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

Store actual component objects



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

def code_obj
  @code_obj
end

#draft_objObject

Store actual component objects



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

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.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/pubid/ieee/identifiers/base.rb', line 118

def self.parse(input)
  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



218
219
220
221
222
223
224
225
226
# File 'lib/pubid/ieee/identifiers/base.rb', line 218

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(Base)
  # 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



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

def code
  code_obj
end

#draftObject



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

def draft
  draft_obj
end

#draft_monthObject

Expose numeric month from draft if available



107
108
109
110
111
# File 'lib/pubid/ieee/identifiers/base.rb', line 107

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



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

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

#to_sObject



228
229
230
# File 'lib/pubid/ieee/identifiers/base.rb', line 228

def to_s
  render(format: :human)
end