Class: Pubid::Iho::Builder

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

Overview

Build IHO identifier objects from parslet parse output.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(parsed) ⇒ Object



23
24
25
# File 'lib/pubid/iho/builder.rb', line 23

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
19
20
21
# File 'lib/pubid/iho/builder.rb', line 7

def build(parsed)
  hash = parsed.is_a?(Array) ? parsed.reduce({}, :merge) : parsed
  type_letter = stringify(hash[:type])

  attrs = {
    code: stringify(hash[:code]),
    appendix: stringify(hash[:appendix]),
    part: stringify(hash[:part]),
    annex: stringify(hash[:annex]),
    supplement: stringify(hash[:supplement]),
    version: stringify(hash[:version]),
  }.compact

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