Class: SwiftValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/swift_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(object, attribute, value) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/swift_validator.rb', line 4

def validate_each(object, attribute, value)
  swift = SWIFTCodeTool::SWIFT.new(value.to_s)
  errors = swift.validation_errors(nil)

  unless errors.empty?
    object.errors[attribute] << (options[:message] || "is not a valid SWIFT code: #{errors.join(", ")}")
  end
end