Module: Pubid::IdentifierMetadata::ClassMethods
- Defined in:
- lib/pubid/identifier_metadata.rb
Instance Method Summary collapse
-
#define_metadata(**attrs) ⇒ Object
Define metadata for an identifier class.
-
#metadata ⇒ Metadata?
Get the metadata for this class.
-
#type_key ⇒ Symbol?
Get the type key from metadata.
-
#type_title ⇒ String?
Get the title from metadata.
Instance Method Details
#define_metadata(**attrs) ⇒ Object
Define metadata for an identifier class
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pubid/identifier_metadata.rb', line 86 def (**attrs) flavor = attrs.fetch(:flavor) do # Extract flavor from class name (e.g., "Pubid::Iso::Identifiers::Foo" -> "iso") name.to_s.split("::")[1..2]&.join("/")&.downcase || "unknown" end # Extract class name (e.g., "Pubid::Iso::Identifiers::Foo" -> "Foo") identifier_class = name.to_s.split("::")&.last @metadata = Metadata.new( flavor: flavor, identifier_class: identifier_class, **attrs, ) end |
#metadata ⇒ Metadata?
Get the metadata for this class
104 105 106 107 108 |
# File 'lib/pubid/identifier_metadata.rb', line 104 def @metadata ||= if superclass.is_a?(Class) && superclass.respond_to?(:metadata) superclass. end end |
#type_key ⇒ Symbol?
Get the type key from metadata
112 113 114 |
# File 'lib/pubid/identifier_metadata.rb', line 112 def type_key &.type_key end |
#type_title ⇒ String?
Get the title from metadata
118 119 120 |
# File 'lib/pubid/identifier_metadata.rb', line 118 def type_title &.title end |