Sha256: 5fb1829182d095251234f696392d9d32d426a9f5a9a2b3cb3b264b29881da700

Contents?: true

Size: 995 Bytes

Versions: 4

Compression:

Stored size: 995 Bytes

Contents

module RockRMS
  module Response
    class Batch < Base
      MAP = {
        name: 'Name',
        control_amount: 'ControlAmount',
        transactions: 'Transactions',
        start_date: 'BatchStartDateTime',
        end_date: 'BatchEndDateTime',
        campus_id: 'CampusId',
        is_campus: 'Campus',
        status: 'Status'
      }.freeze

      def format_single(data)
        response = to_h(MAP, data)
        response[:transactions] = Transaction.format(response[:transactions])
        response[:amount]       = calculate_total(response[:transactions])
        response[:start_date]   = date_parse(response[:start_date])
        response[:end_date]     = date_parse(response[:end_date])
        response
      end

      def calculate_total(transactions)
        transactions.reduce(0) { |sum, txn| sum + txn[:amount] }
      end

      def date_parse(string)
        if string
          DateTime.parse(string)
        else
          nil
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rock_rms-9.13.0 lib/rock_rms/response/batch.rb
rock_rms-9.12.0 lib/rock_rms/response/batch.rb
rock_rms-9.11.0 lib/rock_rms/response/batch.rb
rock_rms-9.10.0 lib/rock_rms/response/batch.rb