Sha256: 87b69a6d8e44d246eb7eb3e72aab65620c69c4fd1a7c22569a980fb9224a0668

Contents?: true

Size: 1.2 KB

Versions: 35

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/hd"

module Renalware
  module HD
    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::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

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
renalware-core-2.0.92 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.91 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.90 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.89 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.88 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.87 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.86 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.85 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.84 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.83 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.82 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.81 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.80 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.79 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.78 app/models/renalware/hd/weekly_diary.rb