Class: Ddate::Converter
- Inherits:
-
Object
- Object
- Ddate::Converter
- Defined in:
- lib/ddate/converter.rb
Constant Summary collapse
- YOLD_BASE =
1970
- YOLD_OFFSET =
1166
- CALENDAR_DAYS_PER_MONTH =
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- DAYS_PER_WEEK =
5
- DAYS_LONG =
%w[Sweetmorn Boomtime Pungenday Prickle-Prickle Setting\ Orange]
- DAYS_SHORT =
%w[SM BT PD PP SO]
- DAYS_PER_SEASON =
Season are 73 days, 4 per 365 year
73
- SEASONS_LONG =
%w[Chaos Discord Confusion Bureaucracy The\ Aftermath]
- SEASONS_SHORT =
%w[Chs Dsc Cfn Bcy Afm]
- APOSTLE_HOLIDAY =
4
- APOSTLE_HOLIDAYS =
fifth of season
%w[Mungday Mojoday Syaday Zaraday Maladay]
- SEASON_HOLIDAY =
49
- SEASON_HOLIDAYS =
50th of season
%w[Choaflux Discoflux Confuflux Bureflux Afflux]
- ST_TIBS_DAY =
once every 4 years, inserted between 59 and 60 Season of Chaos
"Feast of St. Tib's Day"
- EXCLAMATIONS =
[ 'Hail Eris!', 'All Hail Discordia!', 'Kallisti!', 'Fnord.', 'Or not.', 'Wibble.', 'Pzat!', "P'tang!", 'Frink!', 'Slack!', "Praise \"Bob\"!", 'Or kill me.', 'Grudnuk demand sustenance!', 'Keep the Lasagna flying!', 'You are what you see.', 'Or is it?', 'This statement is false.', 'Lies and slander, sire!', 'Hee hee hee!', '' ]
- LINUX_EXCLAMATIONS =
[ 'Hail Eris, Hack Linux!', ]
- NON_LINUX_EXCLAMATIONS =
[ 'This Fruit is not the True Fruit of Discord.', ]
- KILL_BOB_DATE =
Date.new(8661, 6, 5)
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#season ⇒ Object
readonly
Returns the value of attribute season.
-
#yday ⇒ Object
readonly
Returns the value of attribute yday.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #convert ⇒ Object
- #dayname ⇒ Object
- #dayname_short ⇒ Object
- #exclaim ⇒ Object
- #holiday ⇒ Object
-
#initialize(year, month, day, formatter = nil) ⇒ Converter
constructor
A new instance of Converter.
- #kill_bob ⇒ Object
- #leapyear? ⇒ Boolean
- #seasonname ⇒ Object
- #seasonname_short ⇒ Object
- #st_tibs? ⇒ Boolean
- #to_s ⇒ Object
- #weekday ⇒ Object
Constructor Details
#initialize(year, month, day, formatter = nil) ⇒ Converter
Returns a new instance of Converter.
64 65 66 67 68 |
# File 'lib/ddate/converter.rb', line 64 def initialize(year, month, day, formatter = nil) self.date = Date.new(year, month, day) self.formatter = formatter || Ddate::Formatter.new convert end |
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day.
56 57 58 |
# File 'lib/ddate/converter.rb', line 56 def day @day end |
#formatter ⇒ Object
Returns the value of attribute formatter.
55 56 57 |
# File 'lib/ddate/converter.rb', line 55 def formatter @formatter end |
#season ⇒ Object
Returns the value of attribute season.
56 57 58 |
# File 'lib/ddate/converter.rb', line 56 def season @season end |
#yday ⇒ Object
Returns the value of attribute yday.
56 57 58 |
# File 'lib/ddate/converter.rb', line 56 def yday @yday end |
#year ⇒ Object
Returns the value of attribute year.
56 57 58 |
# File 'lib/ddate/converter.rb', line 56 def year @year end |
Instance Method Details
#convert ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ddate/converter.rb', line 70 def convert self.year = DY(date.year) self.day = date.yday - 1 if leapyear? if day == 59 self.day = :st_tibs elsif day > 59 self.day = day - 1 end end self.yday = day self.season = 0 unless day == :st_tibs while (day >= DAYS_PER_SEASON) do self.season = season + 1 self.day = day - DAYS_PER_SEASON end end self end |
#dayname ⇒ Object
138 139 140 |
# File 'lib/ddate/converter.rb', line 138 def dayname DAYS_LONG[weekday] unless st_tibs? end |
#dayname_short ⇒ Object
142 143 144 |
# File 'lib/ddate/converter.rb', line 142 def dayname_short DAYS_SHORT[weekday] unless st_tibs? end |
#exclaim ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/ddate/converter.rb', line 166 def exclaim @exclaims ||= if `uname`.chomp.downcase == 'linux' EXCLAMATIONS.concat(LINUX_EXCLAMATIONS) else EXCLAMATIONS.concat(NON_LINUX_EXCLAMATIONS) end @exclaims.sample end |
#holiday ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/ddate/converter.rb', line 158 def holiday if day == 4 APOSTLE_HOLIDAYS[season] elsif day == 49 SEASON_HOLIDAYS[season] end end |
#kill_bob ⇒ Object
175 176 177 |
# File 'lib/ddate/converter.rb', line 175 def kill_bob (KILL_BOB_DATE - @date).to_i end |
#leapyear? ⇒ Boolean
130 131 132 |
# File 'lib/ddate/converter.rb', line 130 def leapyear? (year % 4) == 2 end |
#seasonname ⇒ Object
146 147 148 |
# File 'lib/ddate/converter.rb', line 146 def seasonname SEASONS_LONG[season] end |
#seasonname_short ⇒ Object
150 151 152 |
# File 'lib/ddate/converter.rb', line 150 def seasonname_short SEASONS_SHORT[season] end |
#st_tibs? ⇒ Boolean
154 155 156 |
# File 'lib/ddate/converter.rb', line 154 def st_tibs? day == :st_tibs end |
#to_s ⇒ Object
94 95 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 |
# File 'lib/ddate/converter.rb', line 94 def to_s if st_tibs? dayactual = nil dayordinal = nil format = :sttibs else dayactual = day+1 dayordinal = dayactual.ordinalize format = :standard end format_arguments = { year: year, day: dayactual, dayth: dayordinal, dayname: dayname, dayname_short: dayname_short, seasonname: seasonname, seasonname_short: seasonname_short, holiday: holiday, exclaim: exclaim, kill_bob: kill_bob, st_tibs_day: ST_TIBS_DAY } formatted = formatter.split(format).map do |part| part % format_arguments end if holiday.nil? && formatted.count > 1 formatted.pop end formatted.compact.join end |
#weekday ⇒ Object
134 135 136 |
# File 'lib/ddate/converter.rb', line 134 def weekday yday % 5 end |