Skip to content

Commit

Permalink
Moar DRYing
Browse files Browse the repository at this point in the history
  • Loading branch information
pezholio committed Oct 19, 2015
1 parent 9aa7dd6 commit 9239b47
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/csvlint/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def print_error(index, error, dump, color)
end
end

def print_errors(errors, dump)
if errors.size > 0
errors.each_with_index { |error, i| print_error(i, error, dump, :red) }
end
end

def return_error(message)
if $stdout.tty?
puts message.colorize(:red)
Expand Down Expand Up @@ -127,17 +133,8 @@ def validate_csv(source, schema, dump)
puts "\r\n#{csv} is #{validator.valid? ? "VALID" : "INVALID"}"
end

if validator.errors.size > 0
validator.errors.each_with_index do |error, i|
print_error(i, error, dump, :red)
end
end

if validator.warnings.size > 0
validator.warnings.each_with_index do |error, i|
print_error(i, error, dump, :yellow)
end
end
print_errors(validator.errors, dump)
print_errors(validator.warnings, dump)

return validator.valid?
end
Expand Down

0 comments on commit 9239b47

Please sign in to comment.