Sha256: 2bfc67943d307e4b63493b8a75b6f274fbbd1203cba7537756be847583a22a00

Contents?: true

Size: 1.35 KB

Versions: 27

Compression:

Stored size: 1.35 KB

Contents

require_dependency "renalware/letters"

# This class is responsible for transforming the attributes
# of a letter.  The resulting attributes can then
# be mass assigned to an ActiveRecord letter object.
module Renalware
  module Letters
    class LetterParamsProcessor
      def initialize(patient)
        @patient = patient
      end

      def call(params)
        params = process_main_recipient_attributes(params)
        process_cc_recipients_attributes(params)
      end

      private

      def process_main_recipient_attributes(params)
        return params unless params.key?(:main_recipient_attributes)

        params.merge(
          main_recipient_attributes: main_recipient_attributes(params)
        )
      end

      def process_cc_recipients_attributes(params)
        return params unless params.key?(:cc_recipients_attributes)

        params.merge(
          cc_recipients_attributes: cc_recipients_attributes(params)
        )
      end

      def main_recipient_attributes(params)
        recipient_attributes(params[:main_recipient_attributes])
      end

      def cc_recipients_attributes(params)
        params[:cc_recipients_attributes].map do |attributes|
          recipient_attributes(attributes)
        end
      end

      def recipient_attributes(params)
        RecipientParamsProcessor.new(@patient).call(params)
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.7 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.5 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.4 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.3 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.2 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.1 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.rc3 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.rc1 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.0.pre.beta12 app/models/renalware/letters/letter_params_processor.rb