Class: Pubid::CenCenelec::SingleIdentifier

Inherits:
Identifier show all
Defined in:
lib/pubid/cen_cenelec/single_identifier.rb

Overview

The second of CEN/CENELEC's two identifier roots (the other is Identifiers::Base); both descend from Pubid::CenCenelec::Identifier so every concrete type is is_a? it.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Identifier

parse

Methods inherited from Identifier

#base_identifier, #eql?, #exclude, from_hash, #hash, #initialize, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, polymorphic_type_map, #render, #resolve_urn_generator, #root, #to_hash, #to_mr_string, #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

.typeString

Generate URN for this identifier

Returns:

  • (String)

    URN representation



17
18
19
# File 'lib/pubid/cen_cenelec/single_identifier.rb', line 17

def self.type
  nil
end

Instance Method Details

#<=>(other) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pubid/cen_cenelec/single_identifier.rb', line 25

def <=>(other)
  return nil unless other.is_a?(SingleIdentifier)

  # Compare by number first
  num_cmp = number.to_s <=> other.number.to_s
  return num_cmp unless num_cmp.zero?

  # Then by part
  part_cmp = (part || Components::Code.new(value: "0")).to_s <=> (other.part || Components::Code.new(value: "0")).to_s
  return part_cmp unless part_cmp.zero?

  # Then by date
  if date && other.date
    date.to_s <=> other.date.to_s
  elsif date
    1
  elsif other.date
    -1
  else
    0
  end
end

#to_s(lang: :en, lang_single: false, **opts) ⇒ Object



21
22
23
# File 'lib/pubid/cen_cenelec/single_identifier.rb', line 21

def to_s(lang: :en, lang_single: false, **opts)
  render(format: :human, lang: lang, lang_single: lang_single, **opts)
end