Skip to content

Commit

Permalink
Change the library to use \r\n as default line-ending. Keep \n as def…
Browse files Browse the repository at this point in the history
…ault in development by supplying default options
  • Loading branch information
ldodds committed Jan 14, 2014
1 parent d5818b3 commit 3462ac0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
6 changes: 3 additions & 3 deletions features/step_definitions/csv_options_steps.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Given(/^I set the delimiter to "(.*?)"$/) do |delimiter|
@csv_options ||= {}
@csv_options ||= default_csv_options
@csv_options["delimiter"] = delimiter
end

Given(/^I set quotechar to "(.*?)"$/) do |doublequote|
@csv_options ||= {}
@csv_options ||= default_csv_options
@csv_options["quotechar"] = doublequote
end

Given(/^I set the line endings to windows$/) do
@csv_options ||= {}
@csv_options ||= default_csv_options
@csv_options["lineterminator"] = "\r\n"
end
4 changes: 2 additions & 2 deletions features/step_definitions/information_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
end

Then(/^the "(.*?)" should be "(.*?)"$/) do |type, encoding|
validator = Csvlint::Validator.new( @url )
validator = Csvlint::Validator.new( @url, default_csv_options )
validator.send(type.to_sym).should == encoding
end

Then(/^the metadata content type should be "(.*?)"$/) do |content_type|
validator = Csvlint::Validator.new( @url )
validator = Csvlint::Validator.new( @url, default_csv_options )
validator.headers['content-type'].should == content_type
end
1 change: 1 addition & 0 deletions features/step_definitions/parse_csv_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
end

When(/^I ask if the CSV is valid$/) do
@csv_options ||= default_csv_options
@validator = Csvlint::Validator.new( @url, @csv_options )
@valid = @validator.valid?
end
Expand Down
3 changes: 2 additions & 1 deletion features/step_definitions/validation_errors_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
When(/^I ask if there are errors$/) do
@validator = Csvlint::Validator.new( @url )
@csv_options ||= default_csv_options
@validator = Csvlint::Validator.new( @url, @csv_options )
@errors = @validator.errors
end

Expand Down
1 change: 1 addition & 0 deletions features/step_definitions/validation_warnings_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
end

When(/^I ask if there are warnings$/) do
@csv_options ||= default_csv_options
@validator = Csvlint::Validator.new( @url, @csv_options )
@warnings = @validator.warnings
end
Expand Down
12 changes: 12 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,16 @@

Spork.each_run do
require 'csvlint'
end

class CustomWorld
def default_csv_options
return {
"lineterminator" => "\n"
}
end
end

World do
CustomWorld.new
end
5 changes: 3 additions & 2 deletions lib/csvlint/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def validate
rescue OpenURI::HTTPError, Errno::ENOENT
build_errors(:not_found, nil)
end
#binding.pry
end

def validate_metadata(io)
Expand All @@ -59,7 +60,7 @@ def parse_csv(io)
reported_invalid_encoding = false

@csv_options[:encoding] = @encoding

wrapper = WrappedIO.new( io )
csv = CSV.new( wrapper , @csv_options )
row = nil
Expand Down Expand Up @@ -120,7 +121,7 @@ def dialect_to_csv_options(dialect)
delimiter = delimiter + " " if !skipinitialspace
return {
:col_sep => delimiter,
:row_sep => ( dialect["lineterminator"] || "\n" ),
:row_sep => ( dialect["lineterminator"] || "\r\n" ),
:quote_char => ( dialect["quotechar"] || '"'),
:skip_blanks => false
}
Expand Down

0 comments on commit 3462ac0

Please sign in to comment.