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 only ‘cast` and optionally `default_identifier_class`.
The build loop:
-
Flattens array-of-hashes input (from Parslet transforms)
-
Iterates each key-value pair
-
Calls ‘cast(key, value)` to convert raw values to component objects
-
Assigns the result to the identifier via ‘send`
-
Silently skips unknown attributes (rescue NoMethodError)
Direct Known Subclasses
Ansi::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 = default_identifier_class) ⇒ Base
constructor
A new instance of Base.
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
#identifier ⇒ Object (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 |