Class: Pubid::Core::Supplement

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/pubid/core/supplement.rb

Direct Known Subclasses

Amendment, Corrigendum

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number:, year: nil) ⇒ Supplement

Creates new supplement with provided update number and optional year

Parameters:

  • number (Integer)
  • year (Integer) (defaults to: nil)


9
10
11
# File 'lib/pubid/core/supplement.rb', line 9

def initialize(number:, year: nil)
  @number, @year = number&.to_i, year&.to_i
end

Instance Attribute Details

#numberObject

Returns the value of attribute number.



4
5
6
# File 'lib/pubid/core/supplement.rb', line 4

def number
  @number
end

#yearObject

Returns the value of attribute year.



4
5
6
# File 'lib/pubid/core/supplement.rb', line 4

def year
  @year
end

Instance Method Details

#<=>(other) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/pubid/core/supplement.rb', line 13

def <=>(other)
  return 0 if year.nil? && other.year

  return year <=> other.year if number == other.number

  (number <=> other.number) || year <=> other.year
end

#render_pubid_numberObject



21
22
23
24
25
26
27
# File 'lib/pubid/core/supplement.rb', line 21

def render_pubid_number
    if @year
      "#{@number}:#{@year}"
    else
      "#{@number}"
    end
end

#render_urn_numberObject



29
30
31
32
33
34
35
# File 'lib/pubid/core/supplement.rb', line 29

def render_urn_number
    if @year
      ":#{@year}:v#{@number}"
    else
      ":#{@number}:v1"
    end
end

#to_hObject



37
38
39
40
# File 'lib/pubid/core/supplement.rb', line 37

def to_h
  { number: number,
    year: year }
end