Class: Pubid::Oiml::Identifier
- Inherits:
-
Identifier
- Object
- Identifier
- Pubid::Oiml::Identifier
- Defined in:
- lib/pubid/oiml/identifier.rb
Direct Known Subclasses
Constant Summary collapse
- OIML_TYPE_MAP =
Maps each concrete identifier's polymorphic_name => class name, so key_value (de)serialization can re-instantiate the correct subclass from the
_typediscriminator. Kept in sync with the Identifiers namespace by a spec assertion (see spec/pubid/oiml/to_hash_spec.rb). { "pubid:oiml:recommendation" => "Pubid::Oiml::Identifiers::Recommendation", "pubid:oiml:basic-publication" => "Pubid::Oiml::Identifiers::BasicPublication", "pubid:oiml:document" => "Pubid::Oiml::Identifiers::Document", "pubid:oiml:guide" => "Pubid::Oiml::Identifiers::Guide", "pubid:oiml:vocabulary" => "Pubid::Oiml::Identifiers::Vocabulary", "pubid:oiml:expert-report" => "Pubid::Oiml::Identifiers::ExpertReport", "pubid:oiml:seminar-report" => "Pubid::Oiml::Identifiers::SeminarReport", "pubid:oiml:amendment" => "Pubid::Oiml::Identifiers::Amendment", "pubid:oiml:errata" => "Pubid::Oiml::Identifiers::Errata", "pubid:oiml:annex" => "Pubid::Oiml::Identifiers::Annex", }.freeze
Class Method Summary collapse
-
.from_hash(data, options = {}) ⇒ Object
lutaml's polymorphic_map only validates
_typeon deserialization; it does not re-instantiate the concrete subclass.
Instance Method Summary collapse
Class Method Details
.from_hash(data, options = {}) ⇒ Object
lutaml's polymorphic_map only validates _type on deserialization; it
does not re-instantiate the concrete subclass. Route by _type so
Pubid::Oiml::Identifier.from_hash(h) returns the right class (and its
nested base_identifier), mirroring Pubid::Iso::Identifier.from_hash.
40 41 42 43 44 45 46 47 48 |
# File 'lib/pubid/oiml/identifier.rb', line 40 def self.from_hash(data, = {}) type = data["_type"] || data[:_type] klass_name = OIML_TYPE_MAP[type] if klass_name klass = Object.const_get(klass_name) return klass.from_hash(data, ) unless klass == self end super end |
Instance Method Details
#to_urn ⇒ Object
50 51 52 |
# File 'lib/pubid/oiml/identifier.rb', line 50 def to_urn UrnGenerator.new(self).generate end |