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.1.1 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.1.0 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.167 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.166 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.165 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.164 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.163 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.162 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.161 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.160 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.159 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.158 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.157 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.156 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.155 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.153 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.152 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.151 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.149 app/models/renalware/hd/scheduling/weekly_diary.rb
renalware-core-2.0.148 app/models/renalware/hd/scheduling/weekly_diary.rb