Class: Pubid::Builder::Base

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

Overview

Base class for all flavor-specific builders.

Provides the shared build loop that converts parsed data into identifier objects. Flavors subclass and override only ‘cast` and optionally `default_identifier_class`.

The build loop:

  1. Flattens array-of-hashes input (from Parslet transforms)

  2. Iterates each key-value pair

  3. Calls ‘cast(key, value)` to convert raw values to component objects

  4. Assigns the result to the identifier via ‘send`

  5. Silently skips unknown attributes (rescue NoMethodError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier_class = default_identifier_class) ⇒ Base

Returns a new instance of Base.



20
21
22
# File 'lib/pubid/builder/base.rb', line 20

def initialize(identifier_class = default_identifier_class)
  @identifier_class = identifier_class
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



18
19
20
# File 'lib/pubid/builder/base.rb', line 18

def identifier
  @identifier
end

Instance Method Details

#build(data) ⇒ Object



24
25
26
27
28
29
# File 'lib/pubid/builder/base.rb', line 24

def build(data)
  data = flatten_array(data) if data.is_a?(Array)
  identifier = @identifier_class.new
  assign_attributes(identifier, data)
  identifier
end