Class: Pubid::IdentifierMetadata::Metadata
- Inherits:
-
Object
- Object
- Pubid::IdentifierMetadata::Metadata
- Defined in:
- lib/pubid/identifier_metadata.rb
Instance Attribute Summary collapse
-
#abbr ⇒ Object
readonly
Returns the value of attribute abbr.
-
#base_class ⇒ Object
readonly
Returns the value of attribute base_class.
-
#flavor ⇒ Object
readonly
Returns the value of attribute flavor.
-
#identifier_class ⇒ Object
readonly
Returns the value of attribute identifier_class.
-
#machine_codes ⇒ Object
readonly
Returns the value of attribute machine_codes.
-
#short ⇒ Object
readonly
Returns the value of attribute short.
-
#stage_codes ⇒ Object
readonly
Returns the value of attribute stage_codes.
-
#supplement_class ⇒ Object
readonly
Returns the value of attribute supplement_class.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type_key ⇒ Object
readonly
Returns the value of attribute type_key.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Additional metadata accessors.
-
#initialize(flavor:, identifier_class:, type_key:, title:, short: nil, abbr: [], base_class: nil, supplement_class: nil, stage_codes: [], machine_codes: {}, **extra_metadata) ⇒ Metadata
constructor
A new instance of Metadata.
-
#matches_code?(code) ⇒ Boolean
Check if this identifier type matches a code.
-
#qualified_class_name ⇒ Object
Fully qualified class name.
-
#slug ⇒ Object
Machine-readable slug for file naming.
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
-
#urn ⇒ Object
URN-style identifier for this type.
Constructor Details
#initialize(flavor:, identifier_class:, type_key:, title:, short: nil, abbr: [], base_class: nil, supplement_class: nil, stage_codes: [], machine_codes: {}, **extra_metadata) ⇒ Metadata
Returns a new instance of Metadata.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pubid/identifier_metadata.rb', line 15 def initialize(flavor:, identifier_class:, type_key:, title:, short: nil, abbr: [], base_class: nil, supplement_class: nil, stage_codes: [], machine_codes: {}, **) @flavor = flavor @identifier_class = identifier_class @type_key = type_key @title = title @short = short @abbr = Array(abbr) @base_class = base_class @supplement_class = supplement_class @stage_codes = Array(stage_codes) @machine_codes = machine_codes @extra_metadata = end |
Instance Attribute Details
#abbr ⇒ Object (readonly)
Returns the value of attribute abbr.
12 13 14 |
# File 'lib/pubid/identifier_metadata.rb', line 12 def abbr @abbr end |
#base_class ⇒ Object (readonly)
Returns the value of attribute base_class.
12 13 14 |
# File 'lib/pubid/identifier_metadata.rb', line 12 def base_class @base_class end |
#flavor ⇒ Object (readonly)
Returns the value of attribute flavor.
12 13 14 |
# File 'lib/pubid/identifier_metadata.rb', line 12 def flavor @flavor end |
#identifier_class ⇒ Object (readonly)
Returns the value of attribute identifier_class.
12 13 14 |
# File 'lib/pubid/identifier_metadata.rb', line 12 def identifier_class @identifier_class end |
#machine_codes ⇒ Object (readonly)
Returns the value of attribute machine_codes.
12 13 14 |
# File 'lib/pubid/identifier_metadata.rb', line 12 def machine_codes @machine_codes end |
#short ⇒ Object (readonly)
Returns the value of attribute short.
12 13 14 |
# File 'lib/pubid/identifier_metadata.rb', line 12 def short @short end |
#stage_codes ⇒ Object (readonly)
Returns the value of attribute stage_codes.
12 13 14 |
# File 'lib/pubid/identifier_metadata.rb', line 12 def stage_codes @stage_codes end |
#supplement_class ⇒ Object (readonly)
Returns the value of attribute supplement_class.
12 13 14 |
# File 'lib/pubid/identifier_metadata.rb', line 12 def supplement_class @supplement_class end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
12 13 14 |
# File 'lib/pubid/identifier_metadata.rb', line 12 def title @title end |
#type_key ⇒ Object (readonly)
Returns the value of attribute type_key.
12 13 14 |
# File 'lib/pubid/identifier_metadata.rb', line 12 def type_key @type_key end |
Instance Method Details
#[](key) ⇒ Object
Additional metadata accessors
56 57 58 |
# File 'lib/pubid/identifier_metadata.rb', line 56 def [](key) @extra_metadata[key] end |
#matches_code?(code) ⇒ Boolean
Check if this identifier type matches a code
47 48 49 50 51 52 53 |
# File 'lib/pubid/identifier_metadata.rb', line 47 def matches_code?(code) return false if code.nil? code_str = code.to_s.downcase.strip @abbr.map(&:to_s).map(&:downcase).include?(code_str) || @type_key.to_s.downcase == code_str end |
#qualified_class_name ⇒ Object
Fully qualified class name
32 33 34 |
# File 'lib/pubid/identifier_metadata.rb', line 32 def qualified_class_name "#{flavor.capitalize}::#{identifier_class}" end |
#slug ⇒ Object
Machine-readable slug for file naming
37 38 39 |
# File 'lib/pubid/identifier_metadata.rb', line 37 def slug "#{flavor}-#{type_key}".downcase.gsub(/[^a-z0-9]+/, "-") end |
#to_h ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pubid/identifier_metadata.rb', line 60 def to_h { flavor: @flavor, identifier_class: @identifier_class, type_key: @type_key, title: @title, short: @short, abbr: @abbr, base_class: @base_class, supplement_class: @supplement_class, stage_codes: @stage_codes, machine_codes: @machine_codes, slug: slug, urn: urn, qualified_class_name: qualified_class_name, }.merge(@extra_metadata) end |
#to_json(*args) ⇒ Object
78 79 80 |
# File 'lib/pubid/identifier_metadata.rb', line 78 def to_json(*args) to_h.to_json(*args) end |
#urn ⇒ Object
URN-style identifier for this type
42 43 44 |
# File 'lib/pubid/identifier_metadata.rb', line 42 def urn "urn:pubid:#{flavor}:type:#{type_key}" end |