Skip to content

Commit

Permalink
Fixed hash empty value bug w/ spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken-g6 committed Feb 29, 2012
1 parent 1213e54 commit 0068c9c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/rubyslim/table_to_hash_converter.rb
Expand Up @@ -27,6 +27,8 @@ def self.create_hash_from_rows(rows)
def self.add_row_to_hash(hash, row)
columns = row.get_elements('td')
raise ArgumentError if columns.size != 2
# Handle empty values.
columns[1].text = '' if columns[1].text == nil
hash[columns[0].text.strip.to_sym] = columns[1].text.strip
end
end
2 changes: 1 addition & 1 deletion spec/table_to_hash_converter_spec.rb
Expand Up @@ -23,7 +23,7 @@ def shouldNotChange(string)
["<table><tr><td>name</td><td>bob</td></tr></table>", {:name=>"bob"}],
[" <table> <tr> <td> name </td> <td> bob </td> </tr> </table> ", {:name=>"bob"}],
["<table><tr><td>name</td><td>bob</td></tr><tr><td>addr</td><td>here</td></tr></table>", {:name=>'bob', :addr=>'here'}],
["<table><tr><td>name</td><td> </td></tr></table>", {:name=>""}],
["<table class=\"hash_table\"><tr><td>name</td><td></td></tr></table>", {:name=>""}],
].each do |table, hash|
it "should match #{table} to #{hash}" do
TableToHashConverter.convert(table).should == hash
Expand Down

0 comments on commit 0068c9c

Please sign in to comment.