Skip to content

Commit

Permalink
Fix CsvSource quotes parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdechakour Mrabet authored and frodrigo committed Dec 2, 2024
1 parent 99310c6 commit 71e92b7
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit 71e92b7

Please sign in to comment.