Class: Renalware::HD::ScheduleDefinition

Inherits:
ApplicationRecord show all
Defined in:
app/models/renalware/hd/schedule_definition.rb

Constant Summary collapse

ABBREV_DAY_NAMES =
%w(Mon Tue Wed Thu Fri Sat Sun).freeze

Instance Method Summary collapse

Instance Method Details

#days_per_weekObject



45
46
47
# File 'app/models/renalware/hd/schedule_definition.rb', line 45

def days_per_week
  days&.length
end

#to_sObject

Render the schedule definition to a human friendly format e.g. “Mon, Wed, Fri AM” to display for example in dropdown lists when choosing a patient’s preferred or actual schedule. Note that we store days of the week as integers starting at 1 (Monday). ABBREV_DAY_NAMES is a 0-based array, so we have to subtract 1 from our days of the week when mapping to a day name string.



35
36
37
38
# File 'app/models/renalware/hd/schedule_definition.rb', line 35

def to_s
  day_names = days.map { |day_number| ABBREV_DAY_NAMES[day_number - 1] }.join(" ")
  "#{day_names} #{diurnal_period.code.upcase}".strip
end