Generates random credit card numbers.
Gets a random credit card number
Forgery(:credit_card).number # => "4539750423451972" Forgery(:credit_card).number(:type => 'Visa', :length => 13) # => "4556180133982"
Supported Options
The credit card type. Defaults to a random selection.
The length of the credit card number. Defaults to the length for the selected card type.
The allowed prefixes for the card number. Defaults to prefixes for the selected card type.
# File lib/forgery/forgery/credit_card.rb, line 34 def self.number(options={}) # find a card by type specified, or select a card randomly card = if options[:type] CARDS.find { |card| card[:type] == options[:type] }.clone else CARDS.random.clone end # merge the remaining options card.merge!(options) # start the number with a prefix for this card number = Forgery::Extend(card[:prefixes]).random # fill in the rest of the number with random digits, leave one space for the check digit number << Forgery::Extend("#" * (card[:length] - number.length - 1)).to_numbers # add the check digit number += check_digit(number) end
Generated with the Darkfish Rdoc Generator 2.