Class: RockRMS::Response::Batch
- Inherits:
-
Base
- Object
- Base
- RockRMS::Response::Batch
show all
- Defined in:
- lib/rock_rms/response/batch.rb
Constant Summary
collapse
- 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
Instance Attribute Summary
Attributes inherited from Base
#data
Instance Method Summary
collapse
Methods inherited from Base
format, #format, #initialize, #to_h
Instance Method Details
#calculate_total(transactions) ⇒ Object
26
27
28
|
# File 'lib/rock_rms/response/batch.rb', line 26
def calculate_total(transactions)
transactions.reduce(0) { |sum, txn| sum + txn[:amount] }
end
|
#date_parse(string) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/rock_rms/response/batch.rb', line 30
def date_parse(string)
if string
DateTime.parse(string)
else
nil
end
end
|
17
18
19
20
21
22
23
24
|
# File 'lib/rock_rms/response/batch.rb', line 17
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
|