Class: Pubid::Doi::Identifier

Inherits:
Identifier
  • Object
show all
Defined in:
lib/pubid/doi/identifier.rb

Direct Known Subclasses

Pubid::Doi::Identifiers::Resource

Constant Summary collapse

DOI_TYPE_MAP =
{
  "pubid:doi:resource" => "Pubid::Doi::Identifiers::Resource",
}.freeze
PUBLISHER =
"DOI"

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Identifier

apply_mappings, #base, #base_document, concrete_class_for, #dated_version_of?, #draft_of?, #drop_supplements, #edition_of?, #eql?, #exclude, from_hash, #has_supplement?, #hash, #includes?, #initialize, #matches?, #mr_all_parts, #mr_edition, #mr_languages, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_subpart, #mr_supplement_suffix, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, polymorphic_type_map, #related_to?, #render, #resolve_urn_generator, #root, #sibling_of?, #supplement_of?, #to_hash, #to_mr_string, #to_slug, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year

Constructor Details

This class inherits a constructor from Pubid::Identifier

Class Method Details

.parse(identifier) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/pubid/doi/identifier.rb', line 34

def self.parse(identifier)
  if identifier.length > Pubid::MAX_INPUT_LENGTH
    raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
  end

  parsed = Parser.parse(identifier)
  Builder.build(parsed)
rescue Parslet::ParseFailed => e
  raise "Failed to parse DOI '#{identifier}': #{e.message}"
end

Instance Method Details

#registrarObject

The numeric registrar subcode (e.g. "1000" for prefix "10.1000").



26
27
28
# File 'lib/pubid/doi/identifier.rb', line 26

def registrar
  prefix.to_s.sub(/\A10\./, "") unless prefix.to_s.empty?
end

#to_s(**opts) ⇒ Object



30
31
32
# File 'lib/pubid/doi/identifier.rb', line 30

def to_s(**opts)
  render(format: :human, **opts)
end