Class: Pubid::Amca::Builder

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

Overview

Builder class for constructing ACMA 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/amca/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/amca/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:



50
51
52
# File 'lib/pubid/amca/builder.rb', line 50

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
# File 'lib/pubid/amca/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

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

  # Check for publication identifier (must come before standard check)
  if parsed_hash[:publication] || parsed_hash[:publication_keyword] || parsed_hash[:revision]
    return build_publication(parsed_hash[:publication] || parsed_hash)
  end

  # Check for interpretation identifier
  if parsed_hash[:interpretation] || parsed_hash[:interpretation_code] || parsed_hash[:interp_keyword]
    return build_interpretation(parsed_hash[:interpretation] || parsed_hash)
  end

  # Handle standard identifier
  if parsed_hash[:standard]
    return build_standard(parsed_hash[:standard])
  end

  # Default: extract attributes and create identifier
  attributes = extract_attributes(parsed_hash)
  identifier_class = determine_identifier_class(attributes)
  identifier_class.new(**attributes)
end