Skip to content

Commit

Permalink
Include columns with blank headers as "untitled_N"
Browse files Browse the repository at this point in the history
  • Loading branch information
seamusabshere committed Nov 26, 2013
1 parent e102e40 commit 6315418
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
@@ -1,3 +1,9 @@
unreleased

* Breaking changes

* Include columns with blank headers as "untitled_N"

3.0.0.rc2 / 2013-08-30

* Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion lib/remote_table/delimited.rb
Expand Up @@ -84,7 +84,7 @@ def headers
if proto_headers
proto_headers.map do |v|
header = RemoteTable.normalize_whitespace v
header.present? ? header : "empty_#{i+=1}"
header.present? ? header : "untitled_#{i+=1}"
end
else
raise "No headers found in first line: #{line.inspect}"
Expand Down
3 changes: 3 additions & 0 deletions lib/remote_table/processed_by_roo.rb
Expand Up @@ -49,6 +49,7 @@ def _each

# create a hash to represent this row
current_headers = ::ActiveSupport::OrderedHash.new
i = 0
if headers == :first_row
(1..spreadsheet.last_column).each do |x|
v = spreadsheet.cell(first_row, x)
Expand All @@ -60,6 +61,8 @@ def _each
v = assume_utf8 v
# 'foobar' is found at column 6
current_headers[v] = x
else
current_headers["untitled_#{i+=1}"] = x
end
end
# "advance the cursor"
Expand Down
8 changes: 4 additions & 4 deletions test/test_old_syntax.rb
Expand Up @@ -5,11 +5,11 @@
{ 'header4' => '1 at 4', 'header5' => '1 at 5', 'header6' => '1 at 6' },
{ 'header4' => '', 'header5' => '', 'header6' => '' },
{ 'header4' => '2 at 4', 'header5' => '2 at 5', 'header6' => '2 at 6' },
]
].map { |hsh| hsh.merge('untitled_1' => '') }
$test2_rows = [
{ 'header4' => '1 at 4', 'header5' => '1 at 5', 'header6' => '1 at 6' },
{ 'header4' => '2 at 4', 'header5' => '2 at 5', 'header6' => '2 at 6' },
]
].map { |hsh| hsh.merge('untitled_1' => '') }
$test2_rows_with_blanks.freeze
$test2_rows.freeze

Expand Down Expand Up @@ -139,7 +139,7 @@
t.rows.all? { |row| row.keys.all?(&:present?) }.must_equal true
# correct values
t.rows.each_with_index do |row, index|
$test2_rows[index].must_equal row.except('row_hash')
$test2_rows[index].except('untitled_1').must_equal row.except('row_hash')
end
end

Expand All @@ -158,7 +158,7 @@
t.rows.all? { |row| row.keys.all?(&:present?) }.must_equal true
# correct values
t.rows.each_with_index do |row, index|
$test2_rows_with_blanks[index].must_equal row.except('row_hash')
$test2_rows_with_blanks[index].except('untitled_1').must_equal row.except('row_hash')
end
end

Expand Down

0 comments on commit 6315418

Please sign in to comment.