Class: Pubid::Plateau::Identifier

Inherits:
Identifier
  • Object
show all
Defined in:
lib/pubid/plateau/identifiers/base.rb

Overview

Base class for all PLATEAU identifiers. Canonical name Pubid::Plateau::Identifier.

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_s, #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

Delegate to the flavor module so callers can use Pubid::Plateau::Identifier.parse consistently with other flavors.



10
11
12
# File 'lib/pubid/plateau/identifiers/base.rb', line 10

def self.parse(identifier)
  Pubid::Plateau.parse(identifier)
end

Instance Method Details

#==(other) ⇒ Object



35
36
37
38
39
40
# File 'lib/pubid/plateau/identifiers/base.rb', line 35

def ==(other)
  return false unless other.class == self.class

  number == other.number &&
    annex == other.annex
end

#base_hashObject

Include type_string and annex in serialization for round-trip compatibility



43
44
45
46
47
48
49
50
51
# File 'lib/pubid/plateau/identifiers/base.rb', line 43

def base_hash
  hash = super
  if self.class.attributes.key?(:type_string) && type_string
    hash[:type] =
      type_string
  end
  hash[:annex] = annex if annex
  hash
end

#formatted_annexObject



31
32
33
# File 'lib/pubid/plateau/identifiers/base.rb', line 31

def formatted_annex
  annex ? "-#{annex}" : ""
end

#formatted_numberObject



27
28
29
# File 'lib/pubid/plateau/identifiers/base.rb', line 27

def formatted_number
  "#%02d" % number
end

#type_stringObject

Subclasses must implement type_string

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/pubid/plateau/identifiers/base.rb', line 23

def type_string
  raise NotImplementedError, "Subclasses must implement type_string"
end