Class: Adventure::Calendar
- Inherits:
-
Object
- Object
- Adventure::Calendar
- Defined in:
- lib/adventure/calendar.rb
Overview
Represents the world's time system.
Constant Summary collapse
- DEFAULT_WEEKDAYS =
['Firstday', 'Secondday', 'Thirdday', 'Fourthday', 'Fifthday', 'Sixthday', 'Seventhday', 'Eighthday', 'Ninthday', 'Tenthday'].freeze
- DEFAULT_MONTHS =
{ 'Month One' => 28, 'Month Two' => 28, 'Month Three' => 28, 'Month Four' => 28, 'Month Five' => 28, 'Month Six' => 28, 'Month Seven' => 28, 'Month Eight' => 28, 'Month Nine' => 28, 'Month Ten' => 28 }.freeze
- DEFAULT_EPOCHS =
{ name: '', abbreviation: '', days: nil }.freeze
Instance Attribute Summary collapse
-
#calendar ⇒ Object
readonly
An Array with each day since year 1 as a Hash with day, month, year, and weekday.
-
#epochs ⇒ Object
readonly
The list of epochs' names and abbreviation.
-
#hours_per_day ⇒ Object
readonly
How many hours a day have.
-
#months ⇒ Object
readonly
The list of months's names.
-
#weekdays ⇒ Object
readonly
The list of weekdays' names.
Instance Method Summary collapse
-
#days_per_week ⇒ Integer
Return how many days a week have.
-
#gregorian ⇒ Object
private
Set calendar variables as Gregorian.
-
#initialize(current_epoch, current_year, current_month, current_day, **opts) ⇒ Calendar
constructor
Create a new instance of Calendar.
- #parse_calendar(current_epoch, current_year, current_month, current_day) ⇒ Object private
-
#to_i ⇒ Integer
Return an Integer as the current date's index in the
calendar. -
#to_s ⇒ String
Return a String with the player's name, gender, species, and total level.
Constructor Details
#initialize(current_epoch, current_year, current_month, current_day, **opts) ⇒ Calendar
Create a new instance of Calendar.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/adventure/calendar.rb', line 48 def initialize(current_epoch, current_year, current_month, current_day, **opts) if opts.key?(:preset) case opts[:preset].strip.downcase when 'gregorian' then gregorian when 'harptos' then harptos else raise StandardError, 'No such preset calendar.' end else @hours_per_day = opts.key?(:hours_per_day) ? opts[:hours_per_day].to_i : 24 @weekdays = opts.key?(:weekdays) ? opts[:weekdays].to_a : DEFAULT_WEEKDAYS @months = opts.key?(:months) ? opts[:months].to_h : DEFAULT_MONTHS @epochs = opts.key?(:epochs) ? opts[:epochs].to_h : DEFAULT_EPOCHS @holidays = opts.key?(:holidays) ? opts[:holidays].to_a : [] end @today_index = parse_calendar(current_epoch, current_year, current_month, current_day) end |
Instance Attribute Details
#calendar ⇒ Object (readonly)
An Array with each day since year 1 as a Hash with day, month, year, and weekday.
34 35 36 |
# File 'lib/adventure/calendar.rb', line 34 def calendar @calendar end |
#epochs ⇒ Object (readonly)
The list of epochs' names and abbreviation.
32 33 34 |
# File 'lib/adventure/calendar.rb', line 32 def epochs @epochs end |
#hours_per_day ⇒ Object (readonly)
How many hours a day have.
26 27 28 |
# File 'lib/adventure/calendar.rb', line 26 def hours_per_day @hours_per_day end |
#months ⇒ Object (readonly)
The list of months's names.
30 31 32 |
# File 'lib/adventure/calendar.rb', line 30 def months @months end |
#weekdays ⇒ Object (readonly)
The list of weekdays' names.
28 29 30 |
# File 'lib/adventure/calendar.rb', line 28 def weekdays @weekdays end |
Instance Method Details
#days_per_week ⇒ Integer
Return how many days a week have.
83 84 85 |
# File 'lib/adventure/calendar.rb', line 83 def days_per_week @weekdays.length end |
#gregorian ⇒ Object (private)
Set calendar variables as Gregorian.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/adventure/calendar.rb', line 96 def gregorian @hours_per_day = 24 @weekdays = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ] @months = { 'January' => 31, 'February' => 28, 'March' => 31, 'April' => 30, 'May' => 31, 'June' => 30, 'July' => 31, 'August' => 31, 'September' => 30, 'October' => 31, 'November' => 30, 'December' => 31 } @epochs = { -1 => { name: 'Before Common Era', abbreviation: 'BCE', days: 4000*365.25 }, 0 => { name: 'Common Era', abbreviation: 'CE', days: nil } } @holidays = [] end |
#parse_calendar(current_epoch, current_year, current_month, current_day) ⇒ Object (private)
89 90 91 92 93 |
# File 'lib/adventure/calendar.rb', line 89 def parse_calendar(current_epoch, current_year, current_month, current_day) @epochs.each_with_index do |epoch, epoch_index| # end end |
#to_i ⇒ Integer
Return an Integer as the current date's index in the calendar.
76 77 78 |
# File 'lib/adventure/calendar.rb', line 76 def to_i @today_index end |
#to_s ⇒ String
Return a String with the player's name, gender, species, and total level.
69 70 71 |
# File 'lib/adventure/calendar.rb', line 69 def to_s "#{@name}, #{@gender.downcase} #{@species.downcase}, level #{@level}" end |