Class: ChinaBank::PayrollTextFile::Line

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/china_bank/payroll_text_file/line.rb

Overview

Describes each line on China Bank’s payroll text file.

Constant Summary collapse

AMOUNT_RANGE =
BigDecimal("0").. BigDecimal("99999999999.99")
TYPES =
{
  credit: "C",
  debit: "D"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account_type: "00", account_number:, amount:, transaction_type:, bank_code: "888") ⇒ Line

Returns a new instance of Line.

Parameters:

  • account_type (String) (defaults to: "00")
  • account_number (String)
  • amount (BigDecimal)
  • transaction_type (String)
  • bank_code (String) (defaults to: "888")

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
# File 'lib/china_bank/payroll_text_file/line.rb', line 33

def initialize(account_type: "00", account_number:, amount:, transaction_type:, bank_code: "888")
  @account_number = 
  @account_type = 
  @bank_code = bank_code
  @transaction_type = transaction_type
  @amount = BigDecimal(amount.to_s)

  raise ArgumentError, errors.full_messages.to_sentence unless valid?
end

Instance Attribute Details

#account_numberObject

Returns the value of attribute account_number.



15
16
17
# File 'lib/china_bank/payroll_text_file/line.rb', line 15

def 
  @account_number
end

#account_typeObject

Returns the value of attribute account_type.



15
16
17
# File 'lib/china_bank/payroll_text_file/line.rb', line 15

def 
  @account_type
end

#amountObject

Returns the value of attribute amount.



15
16
17
# File 'lib/china_bank/payroll_text_file/line.rb', line 15

def amount
  @amount
end

#bank_codeObject

Returns the value of attribute bank_code.



15
16
17
# File 'lib/china_bank/payroll_text_file/line.rb', line 15

def bank_code
  @bank_code
end

#transaction_typeObject

Returns the value of attribute transaction_type.



15
16
17
# File 'lib/china_bank/payroll_text_file/line.rb', line 15

def transaction_type
  @transaction_type
end

Instance Method Details

#to_sString

@example: “*SA1850889513 00000053931.70 D102*”

Returns:

  • (String)


45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/china_bank/payroll_text_file/line.rb', line 45

def to_s
  [
    terminator_character,     # "*"
    ,             # "SA"
    , # "1850889513  "
    spacer,                   # " "
    formatted_amount,         # 00000053931.70
    spacer,                   # " "
    transaction_type,         # "D"
    bank_code,                # "102"
    terminator_character      # "*"
  ].join
end