Created
November 6, 2023 09:22
-
-
Save FrendaWinter/3b9e7587db3881c40e709a857db559b0 to your computer and use it in GitHub Desktop.
Check if the creadit card is vaild with Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'creditcard' | |
# Usage: checkValidCreditCard.rb [card_number_0] [card_number_1] [card_number_???] | |
puts "Usage: checkValidCreditCard.rb [card_number_0] [card_number_1] [card_number_???]" if ARGV.empty? | |
index = 0 | |
while (card_number = ARGV.shift) | |
if card_number.creditcard? | |
puts "---------------------------" | |
puts "Card #{index}: #{card_number}" | |
puts '=> Valid: True' | |
puts "=> Type: #{card_number.creditcard_type}" | |
puts "---------------------------" | |
else | |
puts "---------------------------" | |
puts "Card #{index}: ${card_number}" | |
puts '=> Valid: True' | |
puts '=> Valid: False' | |
puts "---------------------------" | |
end | |
index += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment