Class: MiniDefender::Rules::Currency

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

Constant Summary collapse

CURRENCIES =
Money::Currency.map(&:iso_code).map(&:upcase).uniq

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



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

def self.signature
  'currency'
end

Instance Method Details

#coerce(value) ⇒ Object



12
13
14
# File 'lib/mini_defender/rules/currency.rb', line 12

def coerce(value)
  value.strip.upcase
end

#message(attribute, value, validator) ⇒ Object



20
21
22
# File 'lib/mini_defender/rules/currency.rb', line 20

def message(attribute, value, validator)
  'The value must be a valid ISO-4217 currency code.'
end

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

Returns:



16
17
18
# File 'lib/mini_defender/rules/currency.rb', line 16

def passes?(attribute, value, validator)
  value.is_a?(String) && CURRENCIES.include?(value.strip.upcase)
end