Sha256: 025880b4b77ea214675c68f7953285b8228e63d880b6ebcddfaf2789d3895ef8

Contents?: true

Size: 583 Bytes

Versions: 5

Compression:

Stored size: 583 Bytes

Contents

module RockRMS
  module Response
    class Batch < Base
      MAP = {
        id: 'Id',
        name: 'Name',
        control_amount: 'ControlAmount',
        transactions: 'Transactions'
      }.freeze

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rock_rms-3.2.0 lib/rock_rms/response/batch.rb
rock_rms-3.1.0 lib/rock_rms/response/batch.rb
rock_rms-3.0.2 lib/rock_rms/response/batch.rb
rock_rms-3.0.1 lib/rock_rms/response/batch.rb
rock_rms-3.0.0 lib/rock_rms/response/batch.rb