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.113 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.112 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.111 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.110 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.109 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.108 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.106 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.105 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.104 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.103 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.102 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.101 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.100 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.99 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.98 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.97 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.96 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.95 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.94 app/models/renalware/hd/weekly_diary.rb
renalware-core-2.0.93 app/models/renalware/hd/weekly_diary.rb