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
# 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

  # 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