Class: Pubid::Bsi::Builder

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

Instance Attribute Summary

Attributes inherited from Pubid::Builder::Base

#identifier

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheme) ⇒ Builder

Returns a new instance of Builder.



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

def initialize(scheme)
  @scheme = scheme
end

Class Method Details

.build(parsed_data, scheme = Scheme.new) ⇒ Object



10
11
12
# File 'lib/pubid/bsi/builder.rb', line 10

def self.build(parsed_data, scheme = Scheme.new)
  new(scheme).build(parsed_data)
end

Instance Method Details

#build(data) ⇒ Object



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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/pubid/bsi/builder.rb', line 14

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

  # Store original data to check if BSI prefix was present
  @original_data = data.dup

  # Check for StandaloneAmendment first (very specific pattern)
  if data[:standalone_amendment] || data[:parenthesized_amd]
    return build_standalone_amendment(data)
  end

  # Check for CommitteeDocument
  if data[:committee_document]
    return build_committee_document(data[:committee_document])
  end

  # Check for Index identifier first
  if data[:index_identifier]
    return build_index(data[:index_identifier])
  end

  # Check for Supplementary Index identifier
  if data[:supplementary_index_identifier]
    return build_supplementary_index(data[:supplementary_index_identifier])
  end

  # Check for Explanatory Supplement identifier
  if data[:explanatory_supplement_identifier]
    return build_explanatory_supplement(data[:explanatory_supplement_identifier])
  end

  # Check for Method identifier
  if data[:method_identifier]
    return build_method(data[:method_identifier])
  end

  # Check for Test Method identifier
  if data[:test_method_identifier]
    return build_test_method(data[:test_method_identifier])
  end

  # Check for Section identifier
  if data[:section_identifier]
    return build_section(data[:section_identifier])
  end

  # Check for Detailed Specification identifier
  if data[:detailed_specification]
    return build_detailed_specification(data[:detailed_specification])
  end

  # Check for DISC identifier
  if data[:disc_identifier]
    return build_disc(data[:disc_identifier])
  end

  # Check for Aerospace identifier with letter suffix edition
  if data[:aerospace_identifier]
    return build_aerospace_identifier(data[:aerospace_identifier])
  end

  # Check for SupplementDocument first
  if data[:supplement_document]
    return build_supplement_document(data[:supplement_document])
  end

  # Check for AddendumDocument
  if data[:addendum_document]
    return build_addendum_document(data[:addendum_document])
  end

  # Check for BundledIdentifier
  if data[:bundled_parts] || data[:bundled_list]
    return build_bundled_identifier(data)
  end

  # Check for Set identifier
  if data[:set]
    return build_set(data[:set])
  end

  # Extract supplements before processing
  supplements_data = extract_supplements(data)

  # Check for Value-Added Publication wrapper first
  if data[:pdf_format] || data[:tc_format] || data[:book_format]
    return build_value_added_publication(data, supplements_data)
  end

  # Check for National Annex first (most specific)
  # NationalAnnex can have:
  # - Own supplements: "NA+A1:2012 to BASE"
  # - Adopted string: "NA to BS EN 1234"
  if data[:na_prefix]
    return build_national_annex(data, supplements_data)
  elsif data[:adopted_string]
    # Check for multi-level adoptions
    identifier = build_adopted_identifier(data)

    # Wrap with consolidated if supplements present
    if supplements_data.any?
      identifier = wrap_with_consolidated(identifier,
                                          supplements_data)
    end

    # Wrap with ExpertCommentary if needed
    identifier = wrap_with_expert_commentary(identifier) if data[:expert_commentary]

    return identifier
  end

  # Determine identifier class using Scheme
  identifier = locate_identifier_klass(data).new
  assign_attributes(identifier, data)

  # Wrap with consolidated if supplements present
  if supplements_data.any?
    identifier = wrap_with_consolidated(identifier,
                                        supplements_data)
  end

  # Wrap with ExpertCommentary if needed
  identifier = wrap_with_expert_commentary(identifier) if data[:expert_commentary]

  identifier
end