Class: Bankserv::Set
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Bankserv::Set
show all
- Defined in:
- lib/bankserv/transmission/set.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.from_hash(options) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/bankserv/transmission/set.rb', line 82
def self.from_hash(options)
= options[:data].select{|h| h[:type] == 'header'}.first
trailer_options = options[:data].select{|h| h[:type] == 'trailer'}.first
transaction_options = options[:data].select{|h| not ['header','trailer'].include?(h[:type])}
klass_name = "Bankserv::Transmission::UserSet::#{options[:type].camelize}"
if klass_name == "Bankserv::Transmission::UserSet::Eft"
klass_name = "Bankserv::Transmission::UserSet::Debit" if [:data][:rec_id] == "001"
klass_name = "Bankserv::Transmission::UserSet::Credit" if [:data][:rec_id] == "020"
end
set = klass_name.constantize.new
set.([:data]) if
transaction_options.each do |option|
if option[:data].is_a? Array
set.sets << self.from_hash(option)
else
set.records << Record.new(record_type: option[:type], data: option[:data], reference: option[:data][:user_ref])
end
end
set.build_trailer(trailer_options[:data]) if trailer_options
set
end
|
.partial_class_name ⇒ Object
52
53
54
|
# File 'lib/bankserv/transmission/set.rb', line 52
def self.partial_class_name
self.name.split("::")[-1]
end
|
Instance Method Details
#base_set ⇒ Object
118
119
120
121
|
# File 'lib/bankserv/transmission/set.rb', line 118
def base_set
return parent.base_set if parent
self
end
|
10
11
12
|
# File 'lib/bankserv/transmission/set.rb', line 10
def (options = {})
records.build(record_type: "header", data: options)
end
|
#build_trailer(options = {}) ⇒ Object
14
15
16
|
# File 'lib/bankserv/transmission/set.rb', line 14
def build_trailer(options = {})
records.build(record_type: "trailer", data: options)
end
|
#contained_sets ⇒ Object
110
111
112
|
# File 'lib/bankserv/transmission/set.rb', line 110
def contained_sets
([self] + sets.map(&:contained_sets)).flatten
end
|
#decorate_records ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/bankserv/transmission/set.rb', line 40
def decorate_records
klass = "Absa::H2h::Transmission::#{set_type.camelize}".constantize
records.each do |record|
defaults = klass.record_type(record.record_type).template_options
record.data = defaults.merge(record.data)
record.data[:rec_status] ||= rec_status
end
self.records.each{|rec| rec.save!} end
|
#get_document ⇒ Object
123
124
125
|
# File 'lib/bankserv/transmission/set.rb', line 123
def get_document
base_set.document
end
|
28
29
30
|
# File 'lib/bankserv/transmission/set.rb', line 28
def
records.select {|rec| rec.record_type == "header"}.first
end
|
#number_of_records ⇒ Object
56
57
58
|
# File 'lib/bankserv/transmission/set.rb', line 56
def number_of_records
records.size + sets.inject(0) { |sum, set| sum + set.number_of_records }
end
|
#parent ⇒ Object
18
19
20
|
# File 'lib/bankserv/transmission/set.rb', line 18
def parent
set
end
|
#process ⇒ Object
78
79
80
|
# File 'lib/bankserv/transmission/set.rb', line 78
def process
sets.each{|s| s.process}
end
|
#rec_status ⇒ Object
22
23
24
25
26
|
# File 'lib/bankserv/transmission/set.rb', line 22
def rec_status return document.rec_status if document
return parent.rec_status if parent
"T"
end
|
#record_with_sequence_number(sequence_number) ⇒ Object
114
115
116
|
# File 'lib/bankserv/transmission/set.rb', line 114
def record_with_sequence_number(sequence_number)
transactions.select{|rec| rec.data[:user_sequence_number] == sequence_number}.first
end
|
#set_type ⇒ Object
60
61
62
|
# File 'lib/bankserv/transmission/set.rb', line 60
def set_type
self.class.partial_class_name.underscore
end
|
#to_hash ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/bankserv/transmission/set.rb', line 64
def to_hash
data = []
data << .to_hash if
data << transactions.collect{|rec| rec.to_hash}
data << sets.collect{|s| s.to_hash}
data << trailer.to_hash if trailer
data.flatten!
{
type: set_type,
data: data
}
end
|
#trailer ⇒ Object
32
33
34
|
# File 'lib/bankserv/transmission/set.rb', line 32
def trailer
records.select {|rec| rec.record_type == "trailer"}.first
end
|
#transactions ⇒ Object
36
37
38
|
# File 'lib/bankserv/transmission/set.rb', line 36
def transactions
records.select {|rec| !(["header", "trailer"].include? rec.record_type) }
end
|