# FasterCVS Question/Problem

**URL:** <https://www.ruby-forum.com/t/fastercvs-question-problem/152731>\
**Category:** Ruby\
**Created:** [November 6, 2008, 10:33pm UTC](https://www.ruby-forum.com/t/fastercvs-question-problem/152731 "2008-11-06T22:33:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [November 6, 2008, 10:33pm UTC](https://www.ruby-forum.com/t/fastercvs-question-problem/152731/1 "2008-11-06T22:33:47Z")

</div>

Hello-

I’m using FasterCSV to export order records for our fulfillment partner.  
Here’s a boiled-down snippet of my code:

FasterCSV.open(filename, “w”, :encoding =\> ‘N’) do |csv|  
orders.each do |order|  
order.items.each do |item|  
csv \<\< [  
item.sku.sku,  
item.quantity,  
order.customer.first\_name,  
order.customer.last\_name  
]  
end  
end  
end

If I had one order with two items, I’d expect the output to look like  
this:

SKU001,1,John,Smith  
SKU002,1,John,Smith

However, the output actually looks like this:

“SKU001,SKU002”,1,John,Smith

It seems to be taking the common information and collapsing it onto a  
single row. Does anyone know how to get the output to resemble what I  
was expecting?

Thanks in advance,  
Eric

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [November 6, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/fastercvs-question-problem/152731/2 "2008-11-06T22:52:29Z")

</div>

On Nov 6, 2008, at 3:31 PM, Eric M. wrote:

> Hello-

Howdy.

> I’m using FasterCSV to export order records for our fulfillment  
> partner.  
> Here’s a boiled-down snippet of my code:
> 
> FasterCSV.open(filename, “w”, :encoding =\> ‘N’) do |csv|  
> orders.each do |order|  
> order.items.each do |item|  
> csv \<\< [  
> item.sku.sku,

This line seems fishy. You call sku() twice here.

> this:  
> was expecting?  
> I expect the output to be what you so as well. I ran this code as saw  
> the output we both expected:

#!/usr/bin/env ruby -wKU

require “rubygems”  
require “faster\_csv”

Customer = Struct.new(:first\_name, :last\_name)  
Order = Struct.new(:customer, :items)  
Item = Struct.new(:sku, :quantity)

customer = Customer.new(“John”, “Smith”)  
orders = [Order.new(customer, %w[SKU001 SKU002].map { |s|  
Item.new(s, 1) })]

FasterCSV.open(“example.csv”, “w”, :encoding =\> “N”) do |csv|  
orders.each do |order|  
order.items.each do |item|  
csv \<\< [ item.sku,  
item.quantity,  
order.customer.first\_name,  
order.customer.last\_name ]  
end  
end  
end

**END**

Does that help?

James Edward G. II

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [November 7, 2008, 9:55pm UTC](https://www.ruby-forum.com/t/fastercvs-question-problem/152731/3 "2008-11-07T21:55:36Z")

</div>

Hi James-

Thanks for your reply (and the great library). It turns out this one was  
human error. The FasterCSV library is working flawlessly. Someone had  
entered the string “SKU001,SKU002” as the sku, so the output is exactly  
what one would expect it to be. Incidentally, I called sku twice because  
My Item object has a Sku child which has a sku accessor. Not the best  
naming convention.

Regards,  
Eric

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [November 7, 2008, 9:59pm UTC](https://www.ruby-forum.com/t/fastercvs-question-problem/152731/4 "2008-11-07T21:59:11Z")

</div>

On Nov 7, 2008, at 2:53 PM, Eric M. wrote:

> naming convention.  
> I’m glad to hear that you got it figured out. Good luck with the  
> project.

James Edward G. II
