Class: Pubid::Gb::Builder

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

Overview

Builds a Pubid::Gb::Identifier from a parse tree.

The parser captures the publisher code verbatim (which may already include the "/T" or "/Z" suffix). The builder normalizes: if the suffix is in the publisher_code string, it's split out into the separate mandate attribute so the renderer can recompose either the inline or split form.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(parsed_data) ⇒ Object



13
14
15
# File 'lib/pubid/gb/builder.rb', line 13

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

Instance Method Details

#build(data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pubid/gb/builder.rb', line 17

def build(data)
  publisher_code, mandate = split_mandate(data[:publisher_code].to_s)

  mandate ||= data[:mandate]&.to_s

  Identifiers::Standard.new(
    publisher_code: publisher_code,
    mandate: mandate,
    number: data[:number].to_s,
    part: data[:part]&.to_s,
    date: data[:year] ? ::Pubid::Components::Date.new(year: data[:year].to_s) : nil,
    all_parts: !data[:all_parts].to_s.empty?,
  )
end