Skip to content

Commit

Permalink
Merge pull request #162 from rishijain/update_special_character
Browse files Browse the repository at this point in the history
handled parsing when header has brackets in it
  • Loading branch information
simonoff committed Dec 29, 2014
2 parents 5d13b60 + 8ed5402 commit 126b0bb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/roo/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,15 @@ def row_with(query, return_headers = false)
# makes sure headers is the first part of wildcard search for priority
# ex. if UPC and SKU exist for UPC*SKU search, UPC takes the cake
headers = query.map do |q|
q.map { |i| row.grep(/#{i}/i)[0] }.compact[0]
q.map do |i|
#if header has brackets in it for ex: date(yyyy-mm-dd),
#can add other special characterss to this list.
if i.include?('(')
row.grep(i)[0]
else
row.grep(/#{i}/i)[0]
end
end.compact[0]
end.compact

if headers.length == query.length
Expand Down
Binary file added test/files/advanced_header.ods
Binary file not shown.
9 changes: 9 additions & 0 deletions test/test_roo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ def test_formula_openoffice
end
end

def test_header_with_brackets_excelx
with_each_spreadsheet(:name => 'advanced_header', :format => :openoffice) do |oo|
parsed_head = oo.parse(:headers => true)
assert_equal "Date(yyyy-mm-dd)", oo.cell('A',1)
assert_equal parsed_head[0].keys, ["Date(yyyy-mm-dd)"]
assert_equal parsed_head[0].values, ["Date(yyyy-mm-dd)"]
end
end

def test_formula_excelx
with_each_spreadsheet(:name=>'formula', :format=>:excelx) do |oo|
assert_equal 1, oo.cell('A',1)
Expand Down

0 comments on commit 126b0bb

Please sign in to comment.