0

Hirb gives you some nice outputs in the console, like:

+------------+--------+-----------+-------+--------------------------+
| to_s       | ld     | ajd       | amjd  | asctime                  |
+------------+--------+-----------+-------+--------------------------+
| 2009-03-11 | 155742 | 4909803/2 | 54901 | Wed Mar 11 00:00:00 2009 |
| 2009-04-11 | 155773 | 4909865/2 | 54932 | Sat Apr 11 00:00:00 2009 |
+------------+--------+-----------+-------+--------------------------+

What I'd like to do is find a way to automatically convert this to CSV, but I'm not aware of any Hirb configuration options that allow it. In the meantime I'm just stripping out the bars using find and replace in sublime text, but I'm sure there's a more elegant solution.

Abram
  • 39,950
  • 26
  • 134
  • 184

1 Answers1

0

hirb is just a view framework. The thing you want to manipulate is the data source. Probably your array of objects/hash which contains these data.

Something like this:

CSV.open("path/to/file.csv", "wb") do |csv|
  csv << User.attribute_names
  User.all.each do |user|
    csv << user.attributes.values
  end
end
Babar Al-Amin
  • 3,939
  • 1
  • 16
  • 20
  • Sorry, I realize its view only... What I was hoping for was a way to display CSV format instead of the line and bar format shown above. If I could output that to a file that would be even better.. I already have a perfect hirb output based on a complex (long) join, and I'd prefer not to get the attributes I want into CSV... Is it possible to output the results of a join (with certain attributes selected) into a csv using `.attributes.values`? That would save me a lot of work. – Abram Dec 31 '15 at 14:51