Sha256: 285d090e1e6e5ef8c7b34b64b14afcb174922431f8d111639b7945c4d638e0c8

Contents?: true

Size: 1.02 KB

Versions: 28

Compression:

Stored size: 1.02 KB

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',
        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

28 entries across 28 versions & 1 rubygems

Version Path
rock_rms-7.0.2 lib/rock_rms/response/batch.rb
rock_rms-7.0.1 lib/rock_rms/response/batch.rb
rock_rms-7.0.0 lib/rock_rms/response/batch.rb
rock_rms-6.2.0 lib/rock_rms/response/batch.rb
rock_rms-6.1.0 lib/rock_rms/response/batch.rb
rock_rms-6.0.8 lib/rock_rms/response/batch.rb
rock_rms-6.0.7 lib/rock_rms/response/batch.rb
rock_rms-6.0.6 lib/rock_rms/response/batch.rb
rock_rms-6.0.5 lib/rock_rms/response/batch.rb
rock_rms-6.0.4 lib/rock_rms/response/batch.rb
rock_rms-6.0.3 lib/rock_rms/response/batch.rb
rock_rms-6.0.1 lib/rock_rms/response/batch.rb
rock_rms-6.0.0 lib/rock_rms/response/batch.rb
rock_rms-5.18.0 lib/rock_rms/response/batch.rb
rock_rms-5.17.0 lib/rock_rms/response/batch.rb
rock_rms-5.16.0 lib/rock_rms/response/batch.rb
rock_rms-5.15.0 lib/rock_rms/response/batch.rb
rock_rms-5.14.0 lib/rock_rms/response/batch.rb
rock_rms-5.13.0 lib/rock_rms/response/batch.rb
rock_rms-5.12.0 lib/rock_rms/response/batch.rb