class LSVplus::File

Constants

ATTRIBUTES
FIVE_CHARS_UPPERCASE

Public Instance Methods

add_record(record) click to toggle source
# File lib/lsv_plus/file.rb, line 20
def add_record(record)
  records << record
end
records() click to toggle source
# File lib/lsv_plus/file.rb, line 24
def records
  @records ||= []
end
records_as_string() click to toggle source
# 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() click to toggle source
# File lib/lsv_plus/file.rb, line 28
def to_s
  records_as_string + total_record
end
total() click to toggle source
# File lib/lsv_plus/file.rb, line 46
def total
  records.inject(BigDecimal.new(0)) { |sum, record| sum + record.amount }
end
total_record() click to toggle source
# File lib/lsv_plus/file.rb, line 42
def total_record
  TotalRecordFormatter.call(self)
end
validate(attributes) click to toggle source
Calls superclass method LSVplus::BaseContainer#validate
# 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) click to toggle source
# File lib/lsv_plus/file.rb, line 56
def validate_creator_identification(attributes)
  unless attributes[:creator_identification] =~ FIVE_CHARS_UPPERCASE
    raise InvalidCreatorIdentification, "Does not match #{FIVE_CHARS_UPPERCASE}"
  end
end
validate_lsv_identification(attributes) click to toggle source
# File lib/lsv_plus/file.rb, line 62
def validate_lsv_identification(attributes)
  unless attributes[:lsv_identification] =~ FIVE_CHARS_UPPERCASE
    raise InvalidLSVIdentification, "Does not match #{FIVE_CHARS_UPPERCASE}"
  end
end