class LSVplus::Record

Constants

ATTRIBUTES
MAX_AMOUNT
PROCESSING_MAX_IN_FUTURE
PROCESSING_MAX_IN_PAST
TYPE
VERSION

Public Class Methods

new(attributes) click to toggle source
Calls superclass method LSVplus::BaseContainer::new
# File lib/lsv_plus/record.rb, line 30
def initialize(attributes)
  attributes = attributes.merge type: TYPE, version: VERSION
  validate attributes
  super attributes
end

Public Instance Methods

==(other) click to toggle source
# File lib/lsv_plus/record.rb, line 57
def ==(other)
  ATTRIBUTES.each do |attribute|
    return false unless other.respond_to?(attribute)
    return false unless send(attribute) == other.send(attribute)
  end
  true
end
validate(attributes) click to toggle source
Calls superclass method LSVplus::BaseContainer#validate
# File lib/lsv_plus/record.rb, line 36
def validate(attributes)
  super(attributes)
  validate_processing_date(attributes)
  validate_amount(attributes)
end
validate_amount(attributes) click to toggle source
# File lib/lsv_plus/record.rb, line 51
def validate_amount(attributes)
  if attributes[:amount] > MAX_AMOUNT
    raise InvalidAmount, "Must not be higher than #{MAX_AMOUNT}"
  end
end
validate_processing_date(attributes) click to toggle source
# File lib/lsv_plus/record.rb, line 42
def validate_processing_date(attributes)
  if Date.today + PROCESSING_MAX_IN_FUTURE < attributes[:processing_date]
    raise InvalidProcessingDate, "Max #{PROCESSING_MAX_IN_FUTURE} days in future"
  end
  if Date.today - PROCESSING_MAX_IN_PAST > attributes[:processing_date]
    raise InvalidProcessingDate, "Max #{PROCESSING_MAX_IN_PAST} days in past"
  end
end