Module: Validation

Included in:
Atm, Transaction
Defined in:
lib/validation.rb

Overview

module Validation

Instance Method Summary collapse

Instance Method Details

#amount_in_multiples_of_available_denominations?(amount) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
# File 'lib/validation.rb', line 36

def amount_in_multiples_of_available_denominations?(amount)
  available_denominations = [100, 200, 500]
  if (amount % available_denominations[0]).zero? || (amount % available_denominations[1]).zero? || (amount % available_denominations[2]).zero?
    true
  else
    puts "The amount you entered is not multiple of available denominations\n\n"
    false
  end
end

#card_blocked?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
# File 'lib/validation.rb', line 6

def card_blocked?
  if @current_account.card_blocked == 'true'

    puts 'Your card is Blocked, Please contact your branch'
    welcome_screen
  else
    false
  end
end

#valid_pin?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/validation.rb', line 16

def valid_pin?
  3.times do |n|
    pin = Base64.strict_encode64(take_pin.to_s)
    return true if @current_account.pin == pin

    puts "Incorrect Pin\n\n"
    next unless n == 2

    @accounts_table = CSV.table('account.csv').each do ||
      if [:card_number] == @current_account.card_number
        [:card_blocked] = 'true'
        break
      end
    end
    File.write('account.csv', @accounts_table)
    puts "You have entered wrong pin 3 times\nnow your card is blocked contact your bank for more details.."
    return false
  end
end

#valid_pin_length?(pin) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/validation.rb', line 46

def valid_pin_length?(pin)
  pin.to_s.length == 4
end