Class: Pubid::Ieee::Ire::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/pubid/ieee/ire/builder.rb

Overview

Builder for IRE identifiers

Instance Method Summary collapse

Instance Method Details

#build(parsed) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pubid/ieee/ire/builder.rb', line 8

def build(parsed)
  attributes = {}

  # Extract publisher
  attributes[:publisher] = extract_value(parsed[:publisher])

  # Extract type
  attributes[:type] = extract_value(parsed[:type])

  # Extract number
  number_str = extract_value(parsed[:number])
  if number_str
    attributes[:number] = Components::Code.parse(number_str)
  end

  # Extract year - handle both short (52) and full (1952) formats
  year_str = extract_value(parsed[:year])
  if year_str
    year_int = year_str.to_i
    # Convert 2-digit years to 4-digit (12-63 => 1912-1963)
    if year_int.between?(12, 63)
      year_int += 1900
    end
    attributes[:year] = year_int
  end

  # Override with full_year if present
  full_year_str = extract_value(parsed[:full_year])
  if full_year_str
    attributes[:year] = full_year_str.to_i
  end

  # Create identifier
  Identifier.new(**attributes)
end