Class: RockRMS::Response::Batch

Inherits:
Base
  • Object
show all
Defined in:
lib/rock_rms/response/batch.rb

Constant Summary collapse

MAP =
{
  name: 'Name',
  control_amount: 'ControlAmount',
  transactions: 'Transactions',
  start_date: 'BatchStartDateTime',
  end_date: 'BatchEndDateTime',
  campus_id: 'CampusId',
  is_campus: 'Campus',
  status: 'Status'
}.freeze

Constants inherited from Base

RockRMS::Response::Base::BASE_MAPPING

Instance Attribute Summary

Attributes inherited from Base

#data

Instance Method Summary collapse

Methods inherited from Base

format, #format, #format_attributes, #initialize, #to_h

Constructor Details

This class inherits a constructor from RockRMS::Response::Base

Instance Method Details

#calculate_total(transactions) ⇒ Object



24
25
26
# File 'lib/rock_rms/response/batch.rb', line 24

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

#date_parse(string) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/rock_rms/response/batch.rb', line 28

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

#format_single(data) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/rock_rms/response/batch.rb', line 15

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