Sha256: cc5f649dff4ae9a40bce428794af2ce1a041a5df2882ce3d31c93257a8e513fc

Contents?: true

Size: 1.38 KB

Versions: 149

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

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

149 entries across 149 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.1.0 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.167 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.166 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.165 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.164 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.163 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.162 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.161 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.160 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.159 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.158 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.157 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.156 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.155 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.153 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.152 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.151 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.149 app/models/renalware/letters/letter_params_processor.rb
renalware-core-2.0.148 app/models/renalware/letters/letter_params_processor.rb