Class: LSVplus::File
Defined Under Namespace
Classes: InvalidCreatorIdentification, InvalidLSVIdentification
Constant Summary
collapse
- ATTRIBUTES =
%i(processing_type creation_date creator_identification currency lsv_identification)
- FIVE_CHARS_UPPERCASE =
/\A[A-Z0-9]{5}\z/
Instance Method Summary
collapse
#initialize, #set_attributes, #validate_presence_of_required_attributes
Instance Method Details
#add_record(record) ⇒ Object
20
21
22
|
# File 'lib/lsv_plus/file.rb', line 20
def add_record(record)
records << record
end
|
#records ⇒ Object
24
25
26
|
# File 'lib/lsv_plus/file.rb', line 24
def records
@records ||= []
end
|
#records_as_string ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/lsv_plus/file.rb', line 32
def records_as_string
output = StringIO.new
records.each_with_index do |record, index|
index += 1
output.write RecordFormatter.call(self, record, index)
end
output.rewind
output.read
end
|
#to_s ⇒ Object
28
29
30
|
# File 'lib/lsv_plus/file.rb', line 28
def to_s
records_as_string + total_record
end
|
#total ⇒ Object
46
47
48
|
# File 'lib/lsv_plus/file.rb', line 46
def total
records.inject(BigDecimal.new(0)) { |sum, record| sum + record.amount }
end
|
#validate(attributes) ⇒ Object
50
51
52
53
54
|
# File 'lib/lsv_plus/file.rb', line 50
def validate(attributes)
super(attributes)
validate_creator_identification(attributes)
validate_lsv_identification(attributes)
end
|
#validate_creator_identification(attributes) ⇒ Object
#validate_lsv_identification(attributes) ⇒ Object