Class: Pubid::CenCenelec::Builder

Inherits:
Builder::Base show all
Defined in:
lib/pubid/cen_cenelec/builder.rb

Instance Attribute Summary

Attributes inherited from Builder::Base

#identifier

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Builder::Base

#initialize

Constructor Details

This class inherits a constructor from Pubid::Builder::Base

Class Method Details

.build(parsed_data) ⇒ Object



6
7
8
# File 'lib/pubid/cen_cenelec/builder.rb', line 6

def self.build(parsed_data)
  new.build(parsed_data)
end

Instance Method Details

#build(data) ⇒ Object



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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pubid/cen_cenelec/builder.rb', line 10

def build(data)
  data = flatten_array(data) if data.is_a?(Array)

  # Store data for access in cast method
  @data = data

  # Check if this is a fragment identifier (AMD + FRAG)
  if data[:fragment_number]
    return build_fragment_identifier(data)
  end

  # Check if this is an adopted identifier (EN ISO, EN IEC, etc.)
  if data[:adopted_string]
    # Special case: ENV can adopt ISO/IEC standards
    if data[:publisher]&.to_s == "ENV"
      return build_env_adopted_identifier(data)
    end

    return build_adopted_identifier(data)
  end

  # Check if this is a standalone amendment/corrigendum (slash separator)
  if has_slash_supplements?(data)
    return build_standalone_supplement(data)
  end

  # Implicit adoption: when an EN has no explicit "IEC" prefix but
  # the number falls in the IEC range (60000-79999), treat it as an
  # adoption of the corresponding IEC standard. The lower ISO-only
  # range (1-59999) is intentionally NOT mapped here — too many
  # existing CEN publications (EN Guide N, EN N as a real CEN-assigned
  # number) would change type. Callers who want explicit adoption
  # can still write "EN ISO 12345".
  # (https://github.com/pubid/pubid/issues/249)
  # Skip when parts are present — they would be lost when we rebuild
  # the identifier from just the base number.
  if data[:publisher]&.to_s == "EN" && !data[:adopted_string] &&
     data[:parts].to_a.empty? &&
     (adopted = build_implicit_adoption(data))
    return adopted
  end

  # Extract supplements before building base identifier (only plus/bundled)
  supplements_data = extract_supplements(data)

  # Determine identifier class using the module's lookup helpers
  identifier = locate_identifier_klass(data).new
  assign_attributes(identifier, data)

  # Wrap with consolidated if supplements present (plus/bundled only)
  if supplements_data.any?
    wrap_with_consolidated(identifier, supplements_data)
  else
    identifier
  end
end