# Ruport, reading a csv whose column name have white spaces

**URL:** <https://www.ruby-forum.com/t/ruport-reading-a-csv-whose-column-name-have-white-spaces/192387>\
**Category:** Ruby\
**Created:** [July 29, 2010, 2:30pm UTC](https://www.ruby-forum.com/t/ruport-reading-a-csv-whose-column-name-have-white-spaces/192387 "2010-07-29T14:30:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fourchette](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ac91a4/32.png) [@fourchette](https://www.ruby-forum.com/u/fourchette)\
**Post date:** [July 29, 2010, 2:30pm UTC](https://www.ruby-forum.com/t/ruport-reading-a-csv-whose-column-name-have-white-spaces/192387/1 "2010-07-29T14:30:46Z")

</div>

hi there,

i am not a expert with ruby at all. this is my first post, i do hope  
it’s at right place, please advise otherwise.

i have some dump reporting to do. The input is a csv file. i figured  
rupert could be my friend.

i got it up and running with the following

# instanciate the csv reading stuff

t = Table(“source.csv”)

# remove unnecessary junk

t.remove\_column(“Product/Release Xdor”)

now i want to filter and search data like

Student.find(:all, :conditions =\> { :first\_name =\> “Harvey”, :status =\>  
1 })

(example taken from  
[ActiveRecord::Base](http://api.rubyonrails.org/classes/ActiveRecord/Base.html))

however, the trick is that some of the column names have both the ‘/’  
character and white spaces in them.

so it would look like

t.find(:all, :conditions =\> { :Product/White Darf =\> “Harvey”,  
:Solution/Small Story =\> 0 })

=\> that is giving me syntax errors.

t.find(:all, :conditions =\> { :‘Product/White Darf’ =\> “Harvey”,  
:‘Solution/Small Story’ =\> 0 })

=\> this is throwing instead

$ ruby ruport.rb Anovo-Biometrics-cases.csv  
ruport.rb:86:in `find': wrong number of arguments (2 for 1) (ArgumentError) from ruport.rb:86:in `run’  
from ruport.rb:115

I feel confused. it seriously look like i’ve fallen into some beginners  
issue.

anyone has an idea ?

thanks

---

<div class="post-metadata">

**Author:** ![fourchette](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ac91a4/32.png) [@fourchette](https://www.ruby-forum.com/u/fourchette)\
**Post date:** [July 29, 2010, 8:02pm UTC](https://www.ruby-forum.com/t/ruport-reading-a-csv-whose-column-name-have-white-spaces/192387/2 "2010-07-29T20:02:45Z")

</div>

Hi,

On Thu, Jul 29, 2010 at 8:30 AM, Fourchette Fourchette  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> hi there,
> 
> i am not a expert with ruby at all. this is my first post, i do hope  
> it’s at right place, please advise otherwise.

There’s a Ruport mailing list here:  
[http://groups.google.com/group/ruby-reports](http://groups.google.com/group/ruby-reports)

> anyone has an idea ?

You’re confusing the Ruport API with ActiveRecord. Based on your  
description I’m assuming you’re using Ruport in a stand-alone Ruby  
script and not Rails.

Take a look at Ruport::Data::Table::rows\_with  
([http://api.rubyreports.org/classes/Ruport/Data/Table.html#M000036](http://api.rubyreports.org/classes/Ruport/Data/Table.html#M000036))

You’ll need to do something like:

t.rows\_with(‘Product/White Darf’ =\> ‘Harvey’, ‘Solution/Small Story’ =\>  
0)

> ## thanks
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Try the Ruport mailing list if you need more help.  
([http://groups.google.com/group/ruby-reports](http://groups.google.com/group/ruby-reports))

–Bob

---

<div class="post-metadata">

**Author:** ![fourchette](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ac91a4/32.png) [@fourchette](https://www.ruby-forum.com/u/fourchette)\
**Post date:** [August 3, 2010, 10:59am UTC](https://www.ruby-forum.com/t/ruport-reading-a-csv-whose-column-name-have-white-spaces/192387/3 "2010-08-03T10:59:44Z")

</div>

Thanks bob,

rows\_with does the job. great !

however, i have a field (Solution/Hardware) that i want to use in the  
\_with condition. the trick is that this column often contains a list of  
material such as “PC123,PX0990,ER4554,ER554”, and I want the filter to  
grab only line with “ER” in the string.

So basically, i am looking for the row\_with parameter syntax to use  
myfield like “_ER_”  
instead of  
myfield = “ER”

How can i achieve this ?

thanks

ps: i got my invitation to ruport forum still pending 🙂

---

<div class="post-metadata">

**Author:** ![fourchette](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ac91a4/32.png) [@fourchette](https://www.ruby-forum.com/u/fourchette)\
**Post date:** [August 6, 2010, 5:51pm UTC](https://www.ruby-forum.com/t/ruport-reading-a-csv-whose-column-name-have-white-spaces/192387/4 "2010-08-06T17:51:58Z")

</div>

> rows\_with can also take a block, so you can define how you want the  
> column filtered (in this case I’d probably use a regular expression).  
> Something like:
> 
> t.rows\_with(column\_name) { |col| col ~= /regex/ }
> 
> Take a look at the Ruby API for regular expressions for more info.

wow… can’t wait to test that 🙂

---

<div class="post-metadata">

**Author:** ![fourchette](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ac91a4/32.png) [@fourchette](https://www.ruby-forum.com/u/fourchette)\
**Post date:** [August 3, 2010, 7:19pm UTC](https://www.ruby-forum.com/t/ruport-reading-a-csv-whose-column-name-have-white-spaces/192387/5 "2010-08-03T19:19:16Z")

</div>

On Tue, Aug 3, 2010 at 4:59 AM, Fourchette Fourchette  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> myfield like “_ER_”  
> instead of  
> myfield = “ER”
> 
> How can i achieve this ?

rows\_with can also take a block, so you can define how you want the  
column filtered (in this case I’d probably use a regular expression).  
Something like:

t.rows\_with(column\_name) { |col| col ~= /regex/ }

Take a look at the Ruby API for regular expressions for more info.
