Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/analyzer.rb,
lib/analyzer.rb
Overview
Utility for exporting a mongomapper search
takes a file name where all will be saved to in a csv format
saves csv file
Instance Method Summary collapse
Instance Method Details
#mongo_to_csv(file_path) ⇒ Object
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
# File 'lib/analyzer.rb', line 622 def mongo_to_csv file_path CSV.open(file_path, "wb") do |csv| headers=self[0].class.keys.keys.sort puts headers csv << headers self.each do |c| line=[] headers.each do |h| line<<(c[h]).to_s end csv << line end puts csv end end |
#mongo_to_table ⇒ Object
638 639 640 641 642 643 644 |
# File 'lib/analyzer.rb', line 638 def mongo_to_table file_path=Tempfile.new "test" self.mongo_to_csv file_path r=CSV.table file_path `rm #{file_path}` r end |
#to_table ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/analyzer.rb', line 73 def to_table t=Tempfile.new("foo") self.each do |row| t.write row.to_csv end t.close puts t.path new_table=CSV.table t.path `rm #{t.path}` new_table end |