Class: Adventure::Calendar Deprecated
- Inherits:
-
Object
- Object
- Adventure::Calendar
- Defined in:
- lib/adventure/calendar.rb
Overview
Maybe it will be implemented in the future.
Represents the world's time system.
Constant Summary collapse
- DEFAULT_WEEKDAYS =
List of ten week days with the most generic names.
%w[Firstday Secondday Thirdday Fourthday Fifthday Sixthday Seventhday Eighthday Ninthday Tenthday].freeze
- DEFAULT_MONTHS =
List of ten months with the most generic names.
{ '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 =
Empty list of epochs.
{ name: '', abbreviation: '', days: nil }.freeze
Instance Attribute Summary collapse
-
#calendar ⇒ Object
readonly
Returns the value of attribute calendar.
-
#epochs ⇒ Object
readonly
Returns the value of attribute epochs.
-
#hours_per_day ⇒ Object
readonly
Returns the value of attribute hours_per_day.
-
#months ⇒ Object
readonly
Returns the value of attribute months.
-
#weekdays ⇒ Object
readonly
Returns the value of attribute weekdays.
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
Filler descripton.
-
#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.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/adventure/calendar.rb', line 58 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)
Returns the value of attribute calendar.
44 45 46 |
# File 'lib/adventure/calendar.rb', line 44 def calendar @calendar end |
#epochs ⇒ Object (readonly)
Returns the value of attribute epochs.
41 42 43 |
# File 'lib/adventure/calendar.rb', line 41 def epochs @epochs end |
#hours_per_day ⇒ Object (readonly)
Returns the value of attribute hours_per_day.
32 33 34 |
# File 'lib/adventure/calendar.rb', line 32 def hours_per_day @hours_per_day end |
#months ⇒ Object (readonly)
Returns the value of attribute months.
38 39 40 |
# File 'lib/adventure/calendar.rb', line 38 def months @months end |
#weekdays ⇒ Object (readonly)
Returns the value of attribute weekdays.
35 36 37 |
# File 'lib/adventure/calendar.rb', line 35 def weekdays @weekdays end |
Instance Method Details
#days_per_week ⇒ Integer
Return how many days a week have.
93 94 95 |
# File 'lib/adventure/calendar.rb', line 93 def days_per_week @weekdays.length end |
#gregorian ⇒ Object (private)
Set calendar variables as Gregorian.
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 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/adventure/calendar.rb', line 107 def gregorian @hours_per_day = 24 @weekdays = %w[ 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)
Filler descripton.
100 101 102 103 104 |
# File 'lib/adventure/calendar.rb', line 100 def parse_calendar(_current_epoch, _current_year, _current_month, _current_day) @epochs.each_with_index do |epoch, epoch_index| # Foo bar end end |
#to_i ⇒ Integer
Return an Integer as the current date's index in the calendar.
86 87 88 |
# File 'lib/adventure/calendar.rb', line 86 def to_i @today_index end |
#to_s ⇒ String
Return a String with the player's name, gender, species, and total level.
79 80 81 |
# File 'lib/adventure/calendar.rb', line 79 def to_s "#{@name}, #{@gender.downcase} #{@species.downcase}, level #{@level}" end |