Sha256: fc1da191c51f54608b93b2ecdea335fd14742a9f83b35874b95f9479c4216184

Contents?: true

Size: 1.3 KB

Versions: 52

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/hd"

module Renalware
  module HD
    module Scheduling
      class WeeklyDiary < Diary
        # Overwrite the existing master attribute to ensure it defaults to false
        attribute :master, :boolean, default: false
        belongs_to :master_diary, class_name: "Renalware::HD::Scheduling::MasterDiary"
        validates :week_number,
                  presence: true,
                  uniqueness: { scope: [:year, :hospital_unit_id] },
                  inclusion: { in: 1..53 }
        validates :year, presence: true
        validates :master, inclusion: { in: [false], allow_nil: false }
        validates :master_diary, presence: true
        delegate :to_s, to: :week
        scope :ordered, -> { order(year: :desc, week_number: :desc) }

        def applies_to_current_week?
          today = Time.zone.today
          [today.cweek, today.year] == [week.week_number, week.year]
        end

        def archived?
          false
        end

        class WeeklySlotDecorator < SimpleDelegator
          def master?
            false
          end
        end

        def decorate_slot(slot)
          WeeklySlotDecorator.new(slot)
        end

        def slot_for(*args)
          (slot = super) && decorate_slot(slot)
        end
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
renalware-core-2.0.147 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.146 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.145 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.144 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.143 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.142 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.141 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.140 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.139 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.138 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.137 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.136 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.135 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.134 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.133 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.132 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.131 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.130 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.129 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.128 app/models/renalware/hd/scheduling/weekly_diary.rb