Class: Warpera::Pair
- Inherits:
-
Object
- Object
- Warpera::Pair
- Defined in:
- lib/warpera/pair.rb
Overview
Pairs year and era together for better readability and DRYing
Instance Attribute Summary collapse
-
#era ⇒ :ce, :bce
The era.
-
#year ⇒ Integer
The year as a whole number.
Instance Method Summary collapse
-
#initialize(year:, era:) ⇒ Pair
constructor
Sets the attributes.
-
#to_i ⇒ Integer
Format the year and era into an integer.
-
#to_s ⇒ String
Format the year and era into a string.
Constructor Details
#initialize(year:, era:) ⇒ Pair
Sets the attributes
18 19 20 21 22 23 24 |
# File 'lib/warpera/pair.rb', line 18 def initialize(year:, era:) @year = year @era = era raise ArgumentError, 'Year is not valid' unless valid_year? raise ArgumentError, 'Era is not valid' unless valid_era? end |
Instance Attribute Details
#era ⇒ :ce, :bce
The era
11 12 13 |
# File 'lib/warpera/pair.rb', line 11 def era @era end |
#year ⇒ Integer
The year as a whole number
7 8 9 |
# File 'lib/warpera/pair.rb', line 7 def year @year end |
Instance Method Details
#to_i ⇒ Integer
Format the year and era into an integer
52 53 54 55 56 57 58 |
# File 'lib/warpera/pair.rb', line 52 def to_i if @era == :bce return -1 * @year end @year end |
#to_s ⇒ String
Format the year and era into a string
37 38 39 |
# File 'lib/warpera/pair.rb', line 37 def to_s "#{@year} #{@era.upcase}" end |