Sha256: 6ef93e02c5dc65fb5bb14fd3ddb52207fbee2514405b8001d4f5212eb5c0b357

Contents?: true

Size: 1.01 KB

Versions: 44

Compression:

Stored size: 1.01 KB

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',
        foreign_key: 'ForeignKey'
      }.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

44 entries across 44 versions & 1 rubygems

Version Path
rock_rms-9.9.0 lib/rock_rms/response/batch.rb
rock_rms-9.8.0 lib/rock_rms/response/batch.rb
rock_rms-9.7.0 lib/rock_rms/response/batch.rb
rock_rms-9.6.0 lib/rock_rms/response/batch.rb
rock_rms-9.5.0 lib/rock_rms/response/batch.rb
rock_rms-9.4.0 lib/rock_rms/response/batch.rb
rock_rms-9.3.0 lib/rock_rms/response/batch.rb
rock_rms-9.2.0 lib/rock_rms/response/batch.rb
rock_rms-9.1.0 lib/rock_rms/response/batch.rb
rock_rms-9.0.0 lib/rock_rms/response/batch.rb
rock_rms-8.23.0 lib/rock_rms/response/batch.rb
rock_rms-8.22.0 lib/rock_rms/response/batch.rb
rock_rms-8.21.0 lib/rock_rms/response/batch.rb
rock_rms-8.20.0 lib/rock_rms/response/batch.rb
rock_rms-8.19.0 lib/rock_rms/response/batch.rb
rock_rms-8.18.0 lib/rock_rms/response/batch.rb
rock_rms-8.17.0 lib/rock_rms/response/batch.rb
rock_rms-8.16.0 lib/rock_rms/response/batch.rb
rock_rms-8.15.2 lib/rock_rms/response/batch.rb
rock_rms-8.15.1 lib/rock_rms/response/batch.rb