Module: Pubid::IdentifierMetadata::ClassMethods

Defined in:
lib/pubid/identifier_metadata.rb

Instance Method Summary collapse

Instance Method Details

#define_metadata(**attrs) ⇒ Object

Define metadata for an identifier class

Parameters:

  • attrs (Hash)

    Metadata attributes



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

#metadataMetadata?

Get the metadata for this class

Returns:



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_keySymbol?

Get the type key from metadata

Returns:

  • (Symbol, nil)


112
113
114
# File 'lib/pubid/identifier_metadata.rb', line 112

def type_key
  &.type_key
end

#type_titleString?

Get the title from metadata

Returns:

  • (String, nil)


118
119
120
# File 'lib/pubid/identifier_metadata.rb', line 118

def type_title
  &.title
end