Class: Pubid::Bipm::Builder

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

Overview

Turns the parse tree into the matching concrete identifier. Each root branch tags its subtree with a distinct key, so dispatch is a lookup on which key the parser produced.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(parsed_data) ⇒ Object



9
10
11
# File 'lib/pubid/bipm/builder.rb', line 9

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

Instance Method Details

#build(data) ⇒ Object



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

def build(data)
  if data[:committee_short]
    build_committee(data[:committee_short], form: "short")
  elsif data[:committee_long_en]
    build_committee(data[:committee_long_en], form: "long", language: "E")
  elsif data[:committee_bare]
    # Bare MRA form: no type word, so build_committee yields nil type.
    build_committee(data[:committee_bare], form: "short")
  elsif data[:committee_long_fr]
    build_committee(data[:committee_long_fr], form: "long", language: "F")
  elsif data[:meeting_en]
    build_meeting(data[:meeting_en])
  elsif data[:meeting_fr]
    build_meeting(data[:meeting_fr], language: "F")
  elsif data.key?(:metrologia)
    build_metrologia(data[:metrologia])
  elsif data[:si_brochure]
    build_si_brochure(data[:si_brochure])
  elsif data[:si_brochure_variant]
    build_si_brochure_variant(data[:si_brochure_variant])
  elsif data[:mep]
    build_mep(data[:mep])
  elsif data[:guide]
    build_guide(data[:guide])
  else
    raise "Unrecognized BIPM parse tree: #{data.inspect}"
  end
end