Class: Adventure::Calendar Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/adventure/calendar.rb

Overview

Deprecated.

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

Instance Method Summary collapse

Constructor Details

#initialize(current_epoch, current_year, current_month, current_day, **opts) ⇒ Calendar

Create a new instance of Calendar.

Parameters:

  • current_epoch (Integer)

    The current epoch, as the index of the epochs Hash.

  • current_year (Integer)

    The number of the current year.

  • current_month (Integer)

    The current month, as the index of the months Array.

  • current_day (Integer)

    The number of the current day.

  • opts (Hash)

    A list of optional parameters.

Options Hash (**opts):

  • :hours_per_day (Integer)

    How many hours a day have.

  • :weekdays (Array<String>)

    The list of weekdays' names.

  • :months (Hash)

    The list of months's names, and days in each month.

  • :epochs (Hash)

    The list of epochs' names, abbreviation, and respective day count (or nil, if the current epoch).

  • :holidays (Array<Hash>)

    The list of holidays with date and name.



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

#calendarObject (readonly)

Returns the value of attribute calendar.



44
45
46
# File 'lib/adventure/calendar.rb', line 44

def calendar
  @calendar
end

#epochsObject (readonly)

Returns the value of attribute epochs.



41
42
43
# File 'lib/adventure/calendar.rb', line 41

def epochs
  @epochs
end

#hours_per_dayObject (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

#monthsObject (readonly)

Returns the value of attribute months.



38
39
40
# File 'lib/adventure/calendar.rb', line 38

def months
  @months
end

#weekdaysObject (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_weekInteger

Return how many days a week have.

Returns:

  • (Integer)

    The number of days in a week.



93
94
95
# File 'lib/adventure/calendar.rb', line 93

def days_per_week
  @weekdays.length
end

#gregorianObject (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_iInteger

Return an Integer as the current date's index in the calendar.

Returns:

  • (Integer)

    Current date's index.



86
87
88
# File 'lib/adventure/calendar.rb', line 86

def to_i
  @today_index
end

#to_sString

Return a String with the player's name, gender, species, and total level.

Returns:

  • (String)

    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