Class: Pubid::Ashrae::Builder

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

Overview

Builder class for constructing ASHRAE identifier scheme from parsed data Single Responsibility: Transform parsed data into Scheme objects

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier_class = Identifiers::Base) ⇒ Builder

Returns a new instance of Builder.



10
11
12
# File 'lib/pubid/ashrae/builder.rb', line 10

def initialize(identifier_class = Identifiers::Base)
  @identifier_class = identifier_class
end

Instance Attribute Details

#identifier_classObject (readonly)

Returns the value of attribute identifier_class.



8
9
10
# File 'lib/pubid/ashrae/builder.rb', line 8

def identifier_class
  @identifier_class
end

Class Method Details

.build(parsed) ⇒ Identifiers::Base

Class method to build an identifier from parsed data

Parameters:

  • parsed (Hash, Array)

    the parsed identifier data

Returns:



57
58
59
# File 'lib/pubid/ashrae/builder.rb', line 57

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

Instance Method Details

#build(parsed) ⇒ Scheme

Build a scheme object from parsed data

Parameters:

  • parsed (Hash, Array)

    the parsed identifier data

Returns:

  • (Scheme)

    the constructed scheme object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pubid/ashrae/builder.rb', line 17

def build(parsed)
  # Parslet can return array of hashes - merge them
  parsed_hash = parsed.is_a?(Array) ? merge_parsed_array(parsed) : parsed

  # Check for supplement identifiers first
  if parsed_hash[:errata_keyword]
    return build_errata(parsed_hash)
  elsif parsed_hash[:interpretation_identifier]
    return build_interpretation(parsed_hash[:interpretation_identifier])
  elsif parsed_hash[:combined_addenda]
    return build_combined_addenda(parsed_hash[:combined_addenda])
  elsif parsed_hash[:addenda_package]
    return build_addenda_package(parsed_hash[:addenda_package])
  elsif parsed_hash[:addendum_identifier]
    return build_addendum_from_identifier(parsed_hash[:addendum_identifier])
  elsif parsed_hash[:publisher_addendum]
    return build_publisher_addendum(parsed_hash[:publisher_addendum])
  elsif parsed_hash[:publisher_addendum_copublisher]
    return build_publisher_addendum_copublisher(parsed_hash[:publisher_addendum_copublisher])
  elsif parsed_hash[:publisher_addendum_copublisher_no_type]
    return build_publisher_addendum_copublisher_no_type(parsed_hash[:publisher_addendum_copublisher_no_type])
  elsif parsed_hash[:addendum_no_type]
    return build_addendum_no_type(parsed_hash[:addendum_no_type])
  elsif parsed_hash[:standard_addendum]
    return build_standard_addendum(parsed_hash[:standard_addendum])
  end

  # Handle base identifier
  if parsed_hash[:base]
    parsed_hash = parsed_hash[:base]
  end

  attributes = extract_attributes(parsed_hash)
  identifier_class = determine_identifier_class(attributes)
  identifier_class.new(**attributes)
end