Module: CCheck

Defined in:
lib/ccheck.rb,
lib/ccheck/cli.rb,
lib/ccheck/card.rb,
lib/ccheck/luhn.rb,
lib/ccheck/version.rb

Defined Under Namespace

Classes: CLI, Card, Luhn

Constant Summary collapse

Version =
'0.1.0'

Class Method Summary collapse

Class Method Details

Public: Prints to stdout CC info.

Input - String or Array

If parameter is a String, prints CC info. if parameter is an Array, print their info one by one.



35
36
37
38
39
40
41
# File 'lib/ccheck.rb', line 35

def print input
  if input.is_a? Array
    input.each { |number| puts Card.new(number).to_s }
  else
    puts Card.new(input).to_s
  end
end

.type(number) ⇒ Object

Public: Determines CC type.

number - String

Return String of CC type (Visa, MC). if not found “Unknown”



24
25
26
# File 'lib/ccheck.rb', line 24

def type number
  Card.new(number).type
end

.valid?(number) ⇒ Boolean

Public: Verifies if number is a valid CC number according to Luhn algorithm.

number - String

Return Boolean

Returns:

  • (Boolean)


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

def valid? number
  Luhn.new(number).valid?
end