lib/plastic/core.rb in plastic-0.2.1 vs lib/plastic/core.rb in plastic-0.2.2

- old
+ new

@@ -1,7 +1,7 @@ class Plastic - BRANDS = [:visa, :mastercard, :american_express, :discover] + BRANDS = [:visa, :mastercard, :american_express, :discover, :jcb] attr_accessor :pan, :expiration attr_accessor :track_name, :surname, :given_name, :title attr_accessor :service_code, :cvv2 attr_accessor :track_1, :track_2 @@ -38,15 +38,18 @@ expiration_mm.to_i end def brand case pan - when /^4/ then :visa - when /^5[1-5]/ then :mastercard - when /^677189/ then :mastercard - when /^6011/ then :discover - when /^65/ then :discover - when /^3[47]/ then :american_express + when /^4\d{15}$/ then :visa + when /^5[1-5]\d{14}$/ then :mastercard + when /^677189\d{10}$/ then :mastercard + when /^6011\d{12}$/ then :discover + when /^64[4-9]\d{13}$/ then :discover + when /^65\d{14}$/ then :discover + when /^3[47]\d{13}$/ then :american_express + when /^352[8-9]\d{12}$/ then :jcb + when /^35[3-8]\d{13}$/ then :jcb end end def valid? value_is_present?(pan) && value_is_present?(expiration) && valid_pan? && valid_expiration?