Class: Pubid::Astm::Builder

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

Instance Method Summary collapse

Instance Method Details

#build(parsed_hash) ⇒ Object



6
7
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
# File 'lib/pubid/astm/builder.rb', line 6

def build(parsed_hash)
  # Determine identifier class based on type
  identifier_class = determine_identifier_class(parsed_hash)
  identifier = identifier_class.new

  # Build code component if present
  if parsed_hash[:letter] || parsed_hash[:number]
    identifier.code = build_code(parsed_hash)
  end

  # Set publisher
  # Special case: handle "ISO/ASTMTR" type - split into publisher "ISO/ASTM" and type "TR"
  if parsed_hash[:type]&.to_s == "ISO/ASTMTR"
    identifier.publisher = "ISO/ASTM"
  else
    identifier.publisher = parsed_hash[:publisher].to_s if parsed_hash[:publisher]
    identifier.publisher ||= "ASTM"
  end

  # Set year (convert 2-digit to 4-digit)
  if parsed_hash[:year]
    identifier.year = convert_year(parsed_hash[:year].to_s)
  end

  # Set format suffix with dash prefix
  if parsed_hash[:format_suffix]
    identifier.format_suffix = "-#{parsed_hash[:format_suffix]}"
  end

  # Type-specific attributes
  build_type_specific_attributes(identifier, parsed_hash)

  identifier
end