Skip to content

Commit

Permalink
Merge pull request #13 from theodi/feature-make-sure-streaming-works
Browse files Browse the repository at this point in the history
Make sure streaming works
  • Loading branch information
Sam Pikesley committed Oct 12, 2016
2 parents 8487aee + f52c874 commit cc87818
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/jsontableschema/infer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def infer!
type_matches = []
@rows.each_with_index do |row, i|
break if @row_limit && i > @row_limit
row = row.fields if row.class == CSV::Row

row_length = row.count
headers_length = @headers.count
Expand Down
8 changes: 5 additions & 3 deletions lib/jsontableschema/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def initialize(csv, descriptor, opts = {})
end

def parse_csv(csv)
csv_string = csv.is_a?(Array) ? array_to_csv(csv) : open(csv).read
CSV.parse(csv_string, csv_options)
csv = csv.is_a?(Array) ? StringIO.new(array_to_csv csv) : open(csv)
CSV.new(csv, csv_options)
end

def csv_options
Expand All @@ -41,7 +41,9 @@ def coverted_to_hash(headers, array)
end

def infer_schema(csv)
inferer = JsonTableSchema::Infer.new(csv.headers, csv.to_a)
headers = csv.first.to_h.keys
csv.rewind
inferer = JsonTableSchema::Infer.new(headers, csv)
inferer.schema
end

Expand Down
2 changes: 1 addition & 1 deletion spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"name"=>"id",
"title"=>"",
"description"=>"",
"type"=>"string",
"type"=>"integer",
"format"=>"default"
},
{
Expand Down

0 comments on commit cc87818

Please sign in to comment.