Class: Renalware::HD::Scheduling::DiaryPresenter
- Inherits:
-
Object
- Object
- Renalware::HD::Scheduling::DiaryPresenter
- Defined in:
- app/presenters/renalware/hd/scheduling/diary_presenter.rb
Constant Summary collapse
- NullDiary =
Naught.build do |config| config.black_hole config.define_explicit_conversions config.predicates_return false def master? false end def slot_for(diary_id, diurnal_period_code_id, station_id, day_of_week) NullSlot.new(diary_id, diurnal_period_code_id, station_id, day_of_week) end end
Instance Attribute Summary collapse
-
#master_diary ⇒ Object
readonly
Returns the value of attribute master_diary.
-
#null_diary ⇒ Object
readonly
Returns the value of attribute null_diary.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#weekly_diary ⇒ Object
readonly
Returns the value of attribute weekly_diary.
Instance Method Summary collapse
-
#day_names ⇒ Object
rubocop:enable Layout/LineLength.
-
#each_day(diurnal_period, station) ⇒ Object
rubocop:disable Layout/LineLength.
- #each_diurnal_period ⇒ Object
- #each_station ⇒ Object
-
#initialize(user, weekly_diary) ⇒ DiaryPresenter
constructor
A new instance of DiaryPresenter.
- #station_locations ⇒ Object
- #stations ⇒ Object
Constructor Details
#initialize(user, weekly_diary) ⇒ DiaryPresenter
Returns a new instance of DiaryPresenter.
29 30 31 32 33 34 |
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 29 def initialize(user, weekly_diary) @user = user @weekly_diary = weekly_diary @master_diary = weekly_diary.master_diary @null_diary = NullDiary.new end |
Instance Attribute Details
#master_diary ⇒ Object (readonly)
Returns the value of attribute master_diary.
10 11 12 |
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 10 def master_diary @master_diary end |
#null_diary ⇒ Object (readonly)
Returns the value of attribute null_diary.
10 11 12 |
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 10 def null_diary @null_diary end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
10 11 12 |
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 10 def user @user end |
#weekly_diary ⇒ Object (readonly)
Returns the value of attribute weekly_diary.
10 11 12 |
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 10 def weekly_diary @weekly_diary end |
Instance Method Details
#day_names ⇒ Object
rubocop:enable Layout/LineLength
60 61 62 63 |
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 60 def day_names all_day_names = Time::DAYS_INTO_WEEK.keys all_day_names.take(last_day_of_week) end |
#each_day(diurnal_period, station) ⇒ Object
rubocop:disable Layout/LineLength
47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 47 def each_day(diurnal_period, station) (1..last_day_of_week).each do |day_of_week| diurnal_period_id = diurnal_period.id station_id = station.id valid_from = weekly_diary.week.date_on_first_day_of_week slot = weekly_diary.slot_for(diurnal_period_id, station_id, day_of_week) || master_diary.slot_for(diurnal_period_id, station_id, day_of_week, valid_from: valid_from) || null_diary.slot_for(weekly_diary.id, diurnal_period_id, station_id, day_of_week) yield(slot) if block_given? end end |
#each_diurnal_period ⇒ Object
36 37 38 39 40 |
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 36 def each_diurnal_period DiurnalPeriodCode.all.each do |diurnal_period_code| yield(diurnal_period_code) if block_given? end end |
#each_station ⇒ Object
42 43 44 |
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 42 def each_station stations.each_with_index { |station, index| yield(station, index + 1) if block_given? } end |
#station_locations ⇒ Object
73 74 75 |
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 73 def station_locations StationLocation.all end |
#stations ⇒ Object
65 66 67 68 69 70 71 |
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 65 def stations @stations ||= begin Station.includes(:location).for_unit(hospital_unit_id).ordered.map do |station| StationPresenter.new(station) end end end |