Class: MiniDefender::Rules::ExpiryMonth

Inherits:
MiniDefender::Rule show all
Defined in:
lib/mini_defender/rules/expiry_month.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MiniDefender::Rule

#active?, available?, #bails?, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, make, #priority, #stops?, #with_message

Class Method Details

.signatureObject



4
5
6
# File 'lib/mini_defender/rules/expiry_month.rb', line 4

def self.signature
  'expiry_month'
end

Instance Method Details

#coerce(value) ⇒ Object



8
9
10
# File 'lib/mini_defender/rules/expiry_month.rb', line 8

def coerce(value)
  value.to_s.rjust(2, '0')
end

#message(attribute, value, validator) ⇒ Object



19
20
21
# File 'lib/mini_defender/rules/expiry_month.rb', line 19

def message(attribute, value, validator)
  'Invalid expiry month.'
end

#passes?(attribute, value, validator) ⇒ Boolean

Returns:



12
13
14
15
16
17
# File 'lib/mini_defender/rules/expiry_month.rb', line 12

def passes?(attribute, value, validator)
  return false unless value.to_s.match?(/^\d{1,2}$/)

  value = value.to_i
  value >= 1 && value <= 12
end