Class: Pubid::Plateau::Builder

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(parsed) ⇒ Object



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

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

Instance Method Details

#build(parsed) ⇒ 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
# File 'lib/pubid/plateau/builder.rb', line 10

def build(parsed)
  # Check for annex supplement first
  if parsed[:base_identifier] && parsed[:annex_letter]
    return build_annex(parsed)
  end

  # Determine which class to use based on type
  klass = case parsed[:type].to_s
          when "Handbook"
            Identifiers::Handbook
          when "Technical Report"
            Identifiers::TechnicalReport
          else
            raise "Unknown PLATEAU type: #{parsed[:type]}"
          end

  # Build parameters common to all types
  params = {
    number: parsed[:number].to_s.to_i,
  }

  params[:annex] = parsed[:annex].to_s.to_i if parsed[:annex]
  params[:edition] = parsed[:edition].to_s if parsed[:edition]

  klass.new(**params)
end