Class: DTAFile
- Inherits:
-
Object
- Object
- DTAFile
- Defined in:
- lib/payment_dta/dta_file.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(record) ⇒ Object
- #dta_string ⇒ Object
-
#initialize(path, transaction_number = rand(100000000000).to_s) ⇒ DTAFile
constructor
A new instance of DTAFile.
- #total ⇒ Object
- #write_file ⇒ Object
Constructor Details
#initialize(path, transaction_number = rand(100000000000).to_s) ⇒ DTAFile
Returns a new instance of DTAFile.
8 9 10 11 12 |
# File 'lib/payment_dta/dta_file.rb', line 8 def initialize(path, transaction_number = rand(100000000000).to_s) @transaction_number = transaction_number.to_s @path = path @records = SortedSet.new end |
Instance Attribute Details
#records ⇒ Object (readonly)
Returns the value of attribute records.
6 7 8 |
# File 'lib/payment_dta/dta_file.rb', line 6 def records @records end |
Class Method Details
.create(path) {|dta_file| ... } ⇒ Object
37 38 39 40 41 42 |
# File 'lib/payment_dta/dta_file.rb', line 37 def self.create(path) dta_file = self.new(path) yield dta_file dta_file.write_file dta_file end |
Instance Method Details
#<<(record) ⇒ Object
27 28 29 30 31 |
# File 'lib/payment_dta/dta_file.rb', line 27 def <<(record) record.transaction_number = @transaction_number @records << record recalculate_entry_sequence_numbers end |
#dta_string ⇒ Object
33 34 35 |
# File 'lib/payment_dta/dta_file.rb', line 33 def dta_string (@records.map(&:to_dta) << build_total_record.to_dta) * "\n" << "\n" end |
#total ⇒ Object
21 22 23 24 25 |
# File 'lib/payment_dta/dta_file.rb', line 21 def total @records.inject(0) do |sum, record| sum + BigDecimal.new(record.amount.to_s, 16) end end |
#write_file ⇒ Object
14 15 16 17 18 19 |
# File 'lib/payment_dta/dta_file.rb', line 14 def write_file File.open(@path,"w") do |file| @records.each{|record| file.puts record.to_dta} file.puts build_total_record.to_dta end end |