Sha256: f9d9c76b3b7e3fe70bacbc45a2f5fbdce6e1cd15ab2e811839d200b1dea3fea8

Contents?: true

Size: 1013 Bytes

Versions: 41

Compression:

Stored size: 1013 Bytes

Contents

module RockRMS
  module Response
    class Batch < Base
      MAP = {
        id: 'Id',
        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

41 entries across 41 versions & 1 rubygems

Version Path
rock_rms-5.7.0 lib/rock_rms/response/batch.rb
rock_rms-5.6.0 lib/rock_rms/response/batch.rb
rock_rms-5.5.0 lib/rock_rms/response/batch.rb
rock_rms-5.4.0 lib/rock_rms/response/batch.rb
rock_rms-5.3.0 lib/rock_rms/response/batch.rb
rock_rms-5.2.0 lib/rock_rms/response/batch.rb
rock_rms-5.1.0 lib/rock_rms/response/batch.rb
rock_rms-5.0.0 lib/rock_rms/response/batch.rb
rock_rms-4.18.0 lib/rock_rms/response/batch.rb
rock_rms-4.17.0 lib/rock_rms/response/batch.rb
rock_rms-4.16.0 lib/rock_rms/response/batch.rb
rock_rms-4.15.0 lib/rock_rms/response/batch.rb
rock_rms-4.14.0 lib/rock_rms/response/batch.rb
rock_rms-4.13.0 lib/rock_rms/response/batch.rb
rock_rms-4.12.3 lib/rock_rms/response/batch.rb
rock_rms-4.12.2 lib/rock_rms/response/batch.rb
rock_rms-4.12.1 lib/rock_rms/response/batch.rb
rock_rms-4.11.0 lib/rock_rms/response/batch.rb
rock_rms-4.10.0 lib/rock_rms/response/batch.rb
rock_rms-4.9.0 lib/rock_rms/response/batch.rb