Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CsvSource quotes parser #16

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions datasources/sources/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Settings < Source::SourceSettings
const :url, String
const :uncompress, T.nilable(String)
const :col_sep, String, default: ','
const :quote_char, String, default: '"'
const :id, T::Array[String]
const :lon, String
const :lat, String
Expand All @@ -25,7 +26,7 @@ class Settings < Source::SourceSettings
extend T::Generic
SettingsType = type_member{ { upper: Settings } } # Generic param

def fetch(url, col_sep)
def fetch(url, col_sep, quote_char)
resp = HTTP.follow.get(url)
if !resp.status.success?
raise [url, resp].inspect
Expand All @@ -36,11 +37,11 @@ def fetch(url, col_sep)
reader = Bzip2::FFI::Reader.read(StringIO.new(reader))
end

CSV.parse(reader, headers: true, col_sep: col_sep, quote_char: nil).each(&:to_h)
CSV.parse(reader, headers: true, col_sep: col_sep, quote_char: quote_char).each(&:to_h)
end

def each
super(ENV['NO_DATA'] ? [] : fetch(@settings.url, @settings.col_sep))
super(ENV['NO_DATA'] ? [] : fetch(@settings.url, @settings.col_sep, @settings.quote_char))
end

def map_id(feat)
Expand Down