[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

FasterCVS Question/Problem

Eric Marthinsen

11/6/2008 9:32:00 PM

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
--
Posted via http://www.ruby-....

6 Answers

James Gray

11/6/2008 9:50:00 PM

0

On Nov 6, 2008, at 3:31 PM, Eric Marthinsen 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.

>
> 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?

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 Gray II

Eric Marthinsen

11/7/2008 8:54:00 PM

0

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
--
Posted via http://www.ruby-....

James Gray

11/7/2008 8:57:00 PM

0

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

> 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.

I'm glad to hear that you got it figured out. Good luck with the
project.

James Edward Gray II

james.pablos

8/2/2010 12:30:00 PM

0

On Aug 1, 10:57 pm, "dr.narcolepsy" <jmi...@gmail.com> wrote:

> Thanks for that, but this wasn't as much a poll on the popularity of
> the various planets in our solar system

That would have been more exciting, to be honest.

> as it was a request for
> recommendations for specific DVD packages that parents, here, have
> enjoyed watching with their children.
>

You can't go wrong with the "Walking with Dinosaurs" series. Any child
who doesn't enjoy watching that is dead inside. "Walking with Beasts"
is also good, especially insofar as it covers the Pleistocene epoch
"beasts" -- Glyptodons, Giant camels and sloths, Sabre-toothed lions,
etc. You also get the early hominids.

> I've always liked Venus, myself.

the greenhouse planet

The Lord of Eltingville

8/2/2010 1:00:00 PM

0

James Pablos wrote:
> On Aug 1, 10:57 pm, "dr.narcolepsy" <jmi...@gmail.com> wrote:
>
>> Thanks for that, but this wasn't as much a poll on the popularity of
>> the various planets in our solar system
>
> That would have been more exciting, to be honest.
>
>> as it was a request for
>> recommendations for specific DVD packages that parents, here, have
>> enjoyed watching with their children.
>>
>
> You can't go wrong with the "Walking with Dinosaurs" series. Any child
> who doesn't enjoy watching that is dead inside. "Walking with Beasts"
> is also good, especially insofar as it covers the Pleistocene epoch
> "beasts" -- Glyptodons, Giant camels and sloths, Sabre-toothed lions,
> etc. You also get the early hominids.
>
>> I've always liked Venus, myself.
>
> the greenhouse planet


http://www.youtube.com/watch?v=g...

mr.rapidan

8/2/2010 1:11:00 PM

0

On Aug 2, 9:00 am, The Lord of Eltingville
<tthomas@[REMOVE_TO_REPLY]ogre.net> wrote:
> http://www.youtube.com/watch?v=g...

Ha! That will actually make his hitlist.