Class: Pubid::Jcgm::Builder

Inherits:
Builder::Base show all
Defined in:
lib/pubid/jcgm/builder.rb

Instance Attribute Summary

Attributes inherited from Builder::Base

#identifier

Instance Method Summary collapse

Methods inherited from Builder::Base

#initialize

Constructor Details

This class inherits a constructor from Pubid::Builder::Base

Instance Method Details

#build(parsed_hash) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pubid/jcgm/builder.rb', line 24

def build(parsed_hash)
  identifier = locate_identifier_klass(parsed_hash).new
  assign_attributes(identifier, parsed_hash)

  if identifier.class.attributes.key?(:typed_stage) && identifier.typed_stage.nil?
    default_typed_stage = Jcgm.locate_stage("") ||
      raise(ArgumentError, "Unknown type abbreviation: ''")
    identifier.typed_stage = default_typed_stage
    identifier.stage = default_typed_stage.to_stage if identifier.class.attributes.key?(:stage)
    identifier.type = default_typed_stage.to_type if identifier.class.attributes.key?(:type)
  end

  identifier
end

#locate_identifier_klass(parsed_hash) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pubid/jcgm/builder.rb', line 6

def locate_identifier_klass(parsed_hash)
  if parsed_hash[:base_identifier]
    return Jcgm.locate_type(:amendment)
  end

  if parsed_hash[:gum_number]
    return Jcgm.locate_type(:gum_guide)
  end

  # Standard guide (no type_with_stage, no gum_number).
  # Don't use locate_stage("") — Guide and GumGuide both have
  # abbr: [""], so the result depends on constant iteration order.
  return Jcgm.locate_type(:guide) unless parsed_hash[:type_with_stage]

  typed_stage = locate_typed_stage(parsed_hash[:type_with_stage])
  Jcgm.locate_type(typed_stage.type_code)
end