Class: Pubid::Core::Supplement
- Inherits:
-
Object
- Object
- Pubid::Core::Supplement
- Includes:
- Comparable
- Defined in:
- lib/pubid/core/supplement.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#number ⇒ Object
Returns the value of attribute number.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(number:, year: nil) ⇒ Supplement
constructor
Creates new supplement with provided update number and optional year.
- #render_pubid_number ⇒ Object
- #render_urn_number ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(number:, year: nil) ⇒ Supplement
Creates new supplement with provided update number and optional year
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
#number ⇒ Object
Returns the value of attribute number.
4 5 6 |
# File 'lib/pubid/core/supplement.rb', line 4 def number @number end |
#year ⇒ Object
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_number ⇒ Object
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_number ⇒ Object
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_h ⇒ Object
37 38 39 40 |
# File 'lib/pubid/core/supplement.rb', line 37 def to_h { number: number, year: year } end |