Class: Pubid::Bsi::SingleIdentifier

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

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

Instance Method Details

#<=>(other) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pubid/bsi/single_identifier.rb', line 41

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

#publisherString

Generate URN for this identifier

Returns:

  • (String)

    URN representation



15
16
17
# File 'lib/pubid/bsi/single_identifier.rb', line 15

attribute :publisher, Bsi::Components::Publisher, default: -> {
  Bsi::Components::Publisher.new(body: "BS")
}

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



37
38
39
# File 'lib/pubid/bsi/single_identifier.rb', line 37

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