Class: Pubid::CenCenelec::SingleIdentifier

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Identifier

parse

Methods included from IdentifierFacade

#from_hash, #polymorphic_type_map

Methods inherited from Identifier

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



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

def self.type
  nil
end

Instance Method Details

#<=>(other) ⇒ Object



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

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



24
25
26
# File 'lib/pubid/cen_cenelec/single_identifier.rb', line 24

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