Class: Mcalendar::Schedule
- Inherits:
-
Object
- Object
- Mcalendar::Schedule
- Extended by:
- Forwardable
- Defined in:
- lib/mcalendar/schedule.rb
Defined Under Namespace
Classes: Config_day
Instance Method Summary collapse
- #anniversaries_in_the_month ⇒ Object
- #daily_schedule ⇒ Object
- #days_basic ⇒ Object
- #holidays_in_the_month ⇒ Object
- #holidays_in_the_year(holidays) ⇒ Object
-
#initialize(calendar, config_schedule) ⇒ Schedule
constructor
A new instance of Schedule.
- #setup_schedule ⇒ Object
- #show_anniversaries ⇒ Object
- #show_holidays ⇒ Object
Constructor Details
#initialize(calendar, config_schedule) ⇒ Schedule
Returns a new instance of Schedule.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mcalendar/schedule.rb', line 15 def initialize(calendar, config_schedule) @calendar = calendar @config_schedule = config_schedule @days_config = Hash.new(nil) @holidays = @config_schedule[:holiday] @anniversaries = @config_schedule[:anniversary] @date = @config_schedule[:date] setup_schedule end |
Instance Method Details
#anniversaries_in_the_month ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mcalendar/schedule.rb', line 70 def anniversaries_in_the_month y = format("%4d", first_of_month.year) m = format("%02d", first_of_month.month) regex = /#{y}#{m}\d\d/ @anniversaries.keys.grep(regex).each do |d| @days_config[d].day = Date.parse(d.to_s).day @days_config[d].anniversary_text = @anniversaries[d] end @days_config end |
#daily_schedule ⇒ Object
83 84 85 86 87 |
# File 'lib/mcalendar/schedule.rb', line 83 def daily_schedule daily = @days_config.each_value.map { |val| val } first_of_month.wday.times { daily.unshift(" ") } daily end |
#days_basic ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/mcalendar/schedule.rb', line 47 def days_basic (first_of_month..end_of_month).each do |date| d_sym = date.strftime("%Y%m%d").to_sym @days_config[d_sym] = Config_day.new(date.day, :black, nil, nil) end @days_config end |
#holidays_in_the_month ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mcalendar/schedule.rb', line 56 def holidays_in_the_month y = format("%4d", first_of_month.year) m = format("%02d", first_of_month.month) regex = /#{y}#{m}\d\d/ @holidays.keys.grep(regex).each do |d| @days_config[d].day = Date.parse(d.to_s).day @days_config[d].day_color = :red @days_config[d].holiday_text = @holidays[d] end @days_config end |
#holidays_in_the_year(holidays) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/mcalendar/schedule.rb', line 26 def holidays_in_the_year(holidays) holidays.map do |k,v| year_of_key = Date.parse(k.to_s).year "#{k}: #{v}" if year_of_key == Date.parse(@date.to_s).year end.compact end |
#setup_schedule ⇒ Object
41 42 43 44 45 |
# File 'lib/mcalendar/schedule.rb', line 41 def setup_schedule days_basic holidays_in_the_month anniversaries_in_the_month end |
#show_anniversaries ⇒ Object
37 38 39 |
# File 'lib/mcalendar/schedule.rb', line 37 def show_anniversaries holidays_in_the_year(@anniversaries) end |
#show_holidays ⇒ Object
33 34 35 |
# File 'lib/mcalendar/schedule.rb', line 33 def show_holidays holidays_in_the_year(@holidays) end |