Class: CreditCardDetector::Detector
- Inherits:
-
Object
- Object
- CreditCardDetector::Detector
- Defined in:
- lib/credit_card_detector/detector.rb
Instance Method Summary collapse
- #brand ⇒ Object
- #brand_id ⇒ Object
- #brand_name ⇒ Object
-
#initialize(number) ⇒ Detector
constructor
A new instance of Detector.
- #valid?(*brands) ⇒ Boolean
- #valid_luhn? ⇒ Boolean
Constructor Details
#initialize(number) ⇒ Detector
Returns a new instance of Detector.
6 7 8 |
# File 'lib/credit_card_detector/detector.rb', line 6 def initialize(number) @number = number.to_s.tr('- ', '') end |
Instance Method Details
#brand ⇒ Object
25 26 27 |
# File 'lib/credit_card_detector/detector.rb', line 25 def brand @brand ||= Data.brands.find { |brand| matches_brand? brand } end |
#brand_id ⇒ Object
29 30 31 |
# File 'lib/credit_card_detector/detector.rb', line 29 def brand_id brand.id if brand end |
#brand_name ⇒ Object
33 34 35 |
# File 'lib/credit_card_detector/detector.rb', line 33 def brand_name brand.name if brand end |
#valid?(*brands) ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/credit_card_detector/detector.rb', line 10 def valid?(*brands) brands.compact! if brands.empty? !brand.nil? else validate_brands(brands) brands.include?(brand.id) end end |