class ChristianCalendar
Public Class Methods
new(year=Time.now.year)
click to toggle source
# File lib/christian_calendar.rb, line 13 def initialize(year=Time.now.year) @year = year end
Public Instance Methods
advent_sunday()
click to toggle source
# File lib/christian_calendar.rb, line 90 def advent_sunday() Chronic.parse('sunday', now: christmas).to_date - WEEK * 4 end
ascension_day()
click to toggle source
# File lib/christian_calendar.rb, line 74 def ascension_day() Easter.ascension_day(@year) end
ash_wednesday()
click to toggle source
# File lib/christian_calendar.rb, line 27 def ash_wednesday() Easter.ash_wednesday(@year) end
christmas(year=@year)
click to toggle source
# File lib/christian_calendar.rb, line 94 def christmas(year=@year) Date.new(year, 12, 25) end
easter_sunday()
click to toggle source
# File lib/christian_calendar.rb, line 49 def easter_sunday() Easter.easter(@year) end
Also aliased as: easter
epiphany()
click to toggle source
# File lib/christian_calendar.rb, line 17 def epiphany() christmas(@year - 1) + 12 end
good_friday()
click to toggle source
# File lib/christian_calendar.rb, line 45 def good_friday() Easter.good_friday(@year) end
mothering_sunday()
click to toggle source
# File lib/christian_calendar.rb, line 31 def mothering_sunday() Chronic.parse('sunday', now: ash_wednesday).to_date + WEEK * 3 end
palm_sunday()
click to toggle source
# File lib/christian_calendar.rb, line 41 def palm_sunday() Easter.palm_sunday(@year) end
pentecost()
click to toggle source
# File lib/christian_calendar.rb, line 78 def pentecost() Easter.pentecost(@year) end
Also aliased as: pentecost_sunday
query(s)
click to toggle source
# File lib/christian_calendar.rb, line 98 def query(s) key = s.downcase.gsub(/\W+/,'_').to_sym self.to_h[key] end
st_andrews_day(year=@year)
click to toggle source
# File lib/christian_calendar.rb, line 84 def st_andrews_day(year=@year) Date.new(year, 11, 30) end
Also aliased as: saint_andrews_day
st_davids_day(year=@year)
click to toggle source
# File lib/christian_calendar.rb, line 21 def st_davids_day(year=@year) Date.new(year, 3, 1) end
Also aliased as: saint_davids_day
st_patricks_day(year=@year)
click to toggle source
# File lib/christian_calendar.rb, line 35 def st_patricks_day(year=@year) Date.new(year, 3, 17) end
Also aliased as: saint_patricks_day
to_h()
click to toggle source
# File lib/christian_calendar.rb, line 103 def to_h a = %i(epiphany st_davids_day ash_wednesday mothering_sunday)\ + %i(st_patricks_day palm_sunday good_friday easter easter_sunday)\ + %i(whit_sunday trinity_sunday ascension_day pentecost st_andrews_day)\ + %i(advent_sunday christmas) a.inject({}){|r,day| r.merge(day => method(day).call)} end
to_s()
click to toggle source
# File lib/christian_calendar.rb, line 60 def to_s() a = to_h.sort_by{|k, v| v.to_datetime}.map do |k,v| label = k.to_s.sub(/s(?=_)/,"'s").gsub('_', ' ').split.map(&:capitalize).join(' ') "%+16s: %s" % [label,v.strftime("%d-%b-%Y")] end a.join("\n") end
trinity_sunday()
click to toggle source
# File lib/christian_calendar.rb, line 70 def trinity_sunday() Chronic.parse('sunday', now: pentecost).to_date end
whit_sunday()
click to toggle source
# File lib/christian_calendar.rb, line 55 def whit_sunday() Chronic.parse('sunday', \ now: Chronic.parse('15 May', now: Time.local(@year,1,1))).to_date end