Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError: each_pair for nil:NilClass when using parse with clean: true (CSV) #183

Closed
reshleman opened this issue Mar 11, 2015 · 2 comments

Comments

@reshleman
Copy link
Contributor

Attempting to call parse on a csv spreadsheet with clean: true results in:

NoMethodError: undefined method `each_pair' for nil:NilClass

I'm encountering this on the latest revision of master.

I've created a gist with reproduction steps and a backtrace, in case that's helpful.
https://gist.github.com/reshleman/d8dd9882ca89e01d1bbe

/cc #182

@stevendaniels
Copy link
Contributor

I'm looking into this issue. Thanks for the very helpful gist! 👏

@stevendaniels
Copy link
Contributor

csv does not store cells the way other formats do. Here's the offending method.

# lib/roo/base.rb
def clean_sheet(sheet)
  read_cells(sheet)
  @cell[sheet].each_pair do |coord, value|
      if value.is_a?(::String)
        @cell[sheet][coord] = sanitize_value(value)
      end
   end
  @cleaned[sheet] = true
end

@cell[sheet] should be @cell

This method fixes the issue.

# lib/roo/csv.rb
def clean_sheet(sheet)
  read_cells(sheet)
  @cell[sheet].each_pair do |coord, value|
      if value.is_a?(::String)
        @cell[sheet][coord] = sanitize_value(value)
      end
   end
  @cleaned[sheet] = true
end

Need to add test cases and submit a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants