class RailsFancies::FancyWeeklyCalendarHelper::Calendar
Constants
- HEADER
- SLOT_DURATION
- SLOT_END
- SLOT_START
- START_DAY
Public Class Methods
availability_hash()
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 96 def self.availability_hash { monday: [17, 18, 19, 20, 21, 24, 25, 26, 27], tuesday: [17, 18, 19, 20, 21, 24, 25, 26, 27], wednesday: [17, 18, 19, 20, 21], thursday: [17, 18, 19, 20, 21, 24, 25, 26, 27], friday: [17, 18, 19, 20, 21, 24, 25, 26, 27], sunday: [24, 25, 26, 27] } end
available?(day, slot_num)
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 90 def self.available?(day, slot_num) day_sym = day.strftime("%A").downcase.to_sym slots = Calendar.availability_hash[day_sym] slot_num.in? slots if slots.present? end
Public Instance Methods
day_classes(day, slot_num)
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 63 def day_classes(day, slot_num) classes = [] classes << 'today' if day == Date.today classes << 'notmonth' if day.month != date.month classes << 'available' if Calendar.available?(day, slot_num) classes.empty? ? nil : classes.join(' ') end
day_slot_cell(day, slot_num)
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 59 def day_slot_cell(day, slot_num) content_tag :td, view.capture(day, slot_num, &callback), class: day_classes(day, slot_num) end
header()
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 26 def header content_tag :tr do HEADER.map { |day| content_tag :th, day }.join.html_safe end end
slot_cell(slot_num)
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 44 def slot_cell(slot_num) content_tag :td do slot_num_to_time(slot_num) end end
slot_num_to_time(slot_num)
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 50 def slot_num_to_time(slot_num) start_time = slot_start_time + (slot_num - SLOT_START) * SLOT_DURATION Time.at(start_time).utc.strftime("%H:%M") end
slot_start_time()
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 55 def slot_start_time SLOT_START * SLOT_DURATION end
slots()
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 85 def slots (SLOT_START..SLOT_END) end
table()
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 20 def table content_tag :table, class: "calendar" do header + weekly_rows end end
weekly_rows()
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 32 def weekly_rows slot_num = SLOT_START - 1 weekly_slots.map do |week| slot_num += 1 content_tag :tr do row = [slot_cell(slot_num)] row += week.map { |day| day_slot_cell(day,slot_num) } row.join.html_safe end end.join.html_safe end
weekly_slots()
click to toggle source
# File lib/rails_fancies/fancy_weekly_calendar_helper.rb, line 71 def weekly_slots puts 'start day', start_day, options start_day = options[:start_day] || START_DAY first = date.beginning_of_week(start_day) last = date.end_of_week(start_day) weeks = [] week = (first..last).to_a slots = (SLOT_START..SLOT_END) slots.each do weeks << week end weeks end