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.
8 9 10 11 12 13 |
# File 'lib/valigator/csv/validator.rb', line 8 def initialize(filename) @filename = filename @current_row_number = 0 @errors = [] @config = default_config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/valigator/csv/validator.rb', line 4 def config @config end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/valigator/csv/validator.rb', line 4 def errors @errors end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/valigator/csv/validator.rb', line 4 def filename @filename end |
Instance Method Details
#validate(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/valigator/csv/validator.rb', line 17 def validate( = {}) config.merge! @current_row_number = ()[:headers] ? 1 : 0 ::CSV.foreach(filename, **()) do |row| @current_row_number += 1 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 |