Class: CreditCardDetector::Brand

Inherits:
Object
  • Object
show all
Defined in:
lib/credit_card_detector/brand.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, data) ⇒ Brand

Returns a new instance of Brand.



7
8
9
10
11
# File 'lib/credit_card_detector/brand.rb', line 7

def initialize(id, data)
  @id = id
  @raw_rules = data.fetch(:rules)
  @options = data.fetch(:options, {})
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/credit_card_detector/brand.rb', line 5

def id
  @id
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/credit_card_detector/brand.rb', line 5

def options
  @options
end

Instance Method Details

#luhn?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/credit_card_detector/brand.rb', line 21

def luhn?
  !options.fetch(:skip_luhn, false)
end

#matches?(number) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/credit_card_detector/brand.rb', line 17

def matches?(number)
  rules.any? { |rule| rule.matches? number }
end

#nameObject



13
14
15
# File 'lib/credit_card_detector/brand.rb', line 13

def name
  options.fetch(:brand_name)
end

#rulesObject



25
26
27
# File 'lib/credit_card_detector/brand.rb', line 25

def rules
  @rules ||= @raw_rules.map { |rule| Rule.new rule }
end