class Ddate::Converter
Constants
- APOSTLE_HOLIDAY
- APOSTLE_HOLIDAYS
- CALENDAR_DAYS_PER_MONTH
- DAYS_LONG
- DAYS_PER_SEASON
Season are 73 days, 4 per 365 year
- DAYS_PER_WEEK
- DAYS_SHORT
- EXCLAMATIONS
- KILL_BOB_DATE
- LINUX_EXCLAMATIONS
- NON_LINUX_EXCLAMATIONS
- SEASONS_LONG
- SEASONS_SHORT
- SEASON_HOLIDAY
- SEASON_HOLIDAYS
- ST_TIBS_DAY
- YOLD_BASE
- YOLD_OFFSET
Attributes
date[RW]
day[RW]
formatter[RW]
season[RW]
yday[RW]
year[RW]
Public Class Methods
new(year, month, day, formatter = nil)
click to toggle source
# 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
Public Instance Methods
convert()
click to toggle source
# 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()
click to toggle source
# File lib/ddate/converter.rb, line 138 def dayname DAYS_LONG[weekday] unless st_tibs? end
dayname_short()
click to toggle source
# File lib/ddate/converter.rb, line 142 def dayname_short DAYS_SHORT[weekday] unless st_tibs? end
exclaim()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/ddate/converter.rb, line 175 def kill_bob (KILL_BOB_DATE - @date).to_i end
leapyear?()
click to toggle source
# File lib/ddate/converter.rb, line 130 def leapyear? (year % 4) == 2 end
seasonname()
click to toggle source
# File lib/ddate/converter.rb, line 146 def seasonname SEASONS_LONG[season] end
seasonname_short()
click to toggle source
# File lib/ddate/converter.rb, line 150 def seasonname_short SEASONS_SHORT[season] end
st_tibs?()
click to toggle source
# File lib/ddate/converter.rb, line 154 def st_tibs? day == :st_tibs end
to_s()
click to toggle source
# 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()
click to toggle source
# File lib/ddate/converter.rb, line 134 def weekday yday % 5 end
Private Instance Methods
DY(year)
click to toggle source
# File lib/ddate/converter.rb, line 181 def DY(year) year + YOLD_OFFSET end