Sha256: 4ae3acf563157c8df07a0bdc1e1550460ed4d9ab20f9aecbc3058a80aac59be7

Contents?: true

Size: 771 Bytes

Versions: 3

Compression:

Stored size: 771 Bytes

Contents

require 'active_model'

module AUB
  module Payroll
    class EPFFile::Row
      include ActiveModel::Model

      attr_accessor :account_number, :amount

      validates :account_number, presence: true, length: { is: 12 }
      validates :amount, numericality: { greater_than: 0, less_than_or_equal_to: 99_999_999_999.99 }

      # @param [String] account_number:
      # @param [BigDecimal] amount:
      def initialize(*)
        super
        raise Errors::Invalid, errors.full_messages.to_sentence unless valid?
      end

      def to_s
        [
          '01',
          account_number,
          formatted_amount,
          '0' * 22
        ].join
      end

      private

      def formatted_amount
        format '%014.2f', amount
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aub-payroll-1.1.0 lib/aub/payroll/epf_file/row.rb
aub-payroll-1.0.1 lib/aub/payroll/epf_file/row.rb
aub-payroll-1.0.0 lib/aub/payroll/epf_file/row.rb