Class: Pubid::IdentifierMetadata::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/pubid/identifier_metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#abbrObject (readonly)

Returns the value of attribute abbr.



12
13
14
# File 'lib/pubid/identifier_metadata.rb', line 12

def abbr
  @abbr
end

#base_classObject (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

#flavorObject (readonly)

Returns the value of attribute flavor.



12
13
14
# File 'lib/pubid/identifier_metadata.rb', line 12

def flavor
  @flavor
end

#identifier_classObject (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_codesObject (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

#shortObject (readonly)

Returns the value of attribute short.



12
13
14
# File 'lib/pubid/identifier_metadata.rb', line 12

def short
  @short
end

#stage_codesObject (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_classObject (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

#titleObject (readonly)

Returns the value of attribute title.



12
13
14
# File 'lib/pubid/identifier_metadata.rb', line 12

def title
  @title
end

#type_keyObject (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

Returns:

  • (Boolean)


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_nameObject

Fully qualified class name



32
33
34
# File 'lib/pubid/identifier_metadata.rb', line 32

def qualified_class_name
  "#{flavor.capitalize}::#{identifier_class}"
end

#slugObject

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_hObject



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

#urnObject

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