Class: Valigator::CSV::Validator
- Inherits:
-
Object
- Object
- Valigator::CSV::Validator
- Defined in:
- lib/valigator/csv/validator.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#initialize(filename) ⇒ Validator
constructor
A new instance of Validator.
- #validate(options = {}) ⇒ Object
Constructor Details
#initialize(filename) ⇒ Validator
Returns a new instance of Validator.
10 11 12 13 14 |
# File 'lib/valigator/csv/validator.rb', line 10 def initialize(filename) @filename = filename @errors = [] @config = default_config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/valigator/csv/validator.rb', line 6 def config @config end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/valigator/csv/validator.rb', line 6 def errors @errors end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/valigator/csv/validator.rb', line 6 def filename @filename end |
Instance Method Details
#validate(options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/valigator/csv/validator.rb', line 18 def validate( = {}) config.merge! ::CSV.foreach(filename, ()) do |row| validate_fields row, validate_row row, stop_if_error_limit_reached end rescue ErrorsLimitReachedError rescue ::CSV::MalformedCSVError, Encoding::CompatibilityError, ArgumentError => error raise if (error) errors << CSV::Error.new(error) end |