Class: RailsFancies::FancyWeeklyCalendarHelper::Calendar
- Inherits:
-
Struct
- Object
- Struct
- RailsFancies::FancyWeeklyCalendarHelper::Calendar
- Defined in:
- lib/rails_fancies/fancy_weekly_calendar_helper.rb
Constant Summary collapse
- HEADER =
%w[Time Monday Tuesday Wednesday Thursday Friday Saturday Sunday]
- START_DAY =
:monday
- SLOT_DURATION =
30.minutes
- SLOT_START =
17
- SLOT_END =
31
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#date ⇒ Object
Returns the value of attribute date.
-
#options ⇒ Object
Returns the value of attribute options.
-
#view ⇒ Object
Returns the value of attribute view.
Class Method Summary collapse
Instance Method Summary collapse
- #day_classes(day, slot_num) ⇒ Object
- #day_slot_cell(day, slot_num) ⇒ Object
- #header ⇒ Object
- #slot_cell(slot_num) ⇒ Object
- #slot_num_to_time(slot_num) ⇒ Object
- #slot_start_time ⇒ Object
- #slots ⇒ Object
- #table ⇒ Object
- #weekly_rows ⇒ Object
- #weekly_slots ⇒ Object
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback
11 12 13 |
# File 'lib/rails_fancies/fancy_weekly_calendar_helper.rb', line 11 def callback @callback end |
#date ⇒ Object
Returns the value of attribute date
11 12 13 |
# File 'lib/rails_fancies/fancy_weekly_calendar_helper.rb', line 11 def date @date end |
#options ⇒ Object
Returns the value of attribute options
11 12 13 |
# File 'lib/rails_fancies/fancy_weekly_calendar_helper.rb', line 11 def @options end |
#view ⇒ Object
Returns the value of attribute view
11 12 13 |
# File 'lib/rails_fancies/fancy_weekly_calendar_helper.rb', line 11 def view @view end |
Class Method Details
.availability_hash ⇒ Object
96 97 98 99 100 101 102 103 104 |
# 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) ⇒ Boolean
90 91 92 93 94 |
# 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 |
Instance Method Details
#day_classes(day, slot_num) ⇒ Object
63 64 65 66 67 68 69 |
# 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) ⇒ Object
59 60 61 |
# 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 ⇒ Object
26 27 28 29 30 |
# 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) ⇒ Object
44 45 46 47 48 |
# 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) ⇒ Object
50 51 52 53 |
# 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 ⇒ Object
55 56 57 |
# File 'lib/rails_fancies/fancy_weekly_calendar_helper.rb', line 55 def slot_start_time SLOT_START * SLOT_DURATION end |
#slots ⇒ Object
85 86 87 |
# File 'lib/rails_fancies/fancy_weekly_calendar_helper.rb', line 85 def slots (SLOT_START..SLOT_END) end |
#table ⇒ Object
20 21 22 23 24 |
# 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 ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# 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 ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rails_fancies/fancy_weekly_calendar_helper.rb', line 71 def weekly_slots puts 'start day', start_day, start_day = [: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 |