Class: Pubid::Builder::Base
- Inherits:
-
Object
- Object
- Pubid::Builder::Base
- 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:
select_class(data)to dispatch by data shape (default returnsdefault_identifier_class).cast(key, value)to transform raw parsed values into components.handle_key(identifier, key, value)for non-attribute side effects.
The build loop:
- Flattens array-of-hashes input (from Parslet transforms)
- Asks
select_class(data)for the identifier class - Iterates each key-value pair
- Calls
cast(key, value)to convert raw values to component objects - Assigns the result to the identifier via setter
- Silently skips unknown attributes
Direct Known Subclasses
Ansi::Builder, Api::Builder, Pubid::Bsi::Builder, CenCenelec::Builder, Idf::Builder, Iec::Builder, Iso::Builder, Jcgm::Builder, Nist::Builder, Sae::Builder
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Instance Method Summary collapse
- #build(data) ⇒ Object
-
#initialize(identifier_class = nil) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(identifier_class = nil) ⇒ Base
Returns a new instance of Base.
24 25 26 |
# File 'lib/pubid/builder/base.rb', line 24 def initialize(identifier_class = nil) @identifier_class = identifier_class end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
22 23 24 |
# File 'lib/pubid/builder/base.rb', line 22 def identifier @identifier end |
Instance Method Details
#build(data) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/pubid/builder/base.rb', line 28 def build(data) data = flatten_array(data) if data.is_a?(Array) identifier_class = @identifier_class || select_class(data) identifier = identifier_class.new assign_attributes(identifier, data) identifier end |