Class: Pubid::Iala::Builder

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

Overview

Builds an IALA identifier object from the Parslet parse tree.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(parsed) ⇒ Object



20
21
22
# File 'lib/pubid/iala/builder.rb', line 20

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

Instance Method Details

#build(parsed) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/pubid/iala/builder.rb', line 7

def build(parsed)
  hash = parsed
  type_letter = stringify(hash[:type_letter])&.upcase

  attrs = {
    number:   build_number(hash),
    edition:  stringify(hash.dig(:edition, :edition_value)),
    language: stringify(hash.dig(:language_group, :language))&.upcase,
  }.compact

  Iala.identifier_klass_for_type_letter(type_letter).new(**attrs)
end