Class: Template::Csv

Inherits:
Object
  • Object
show all
Defined in:
lib/template.rb

Overview

handles creating and writing CSV output files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, attr_labels) ⇒ Csv

dir: basename of root directory attr_labels: array of attributes labels as strings



15
16
17
18
19
# File 'lib/template.rb', line 15

def initialize(dir, attr_labels)
  @file_name = "tmp/output/#{dir}_#{Time.now.to_i}.csv"
  @file = File.new(@file_name, 'w')
  @file.puts(attr_labels.join(','))
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



11
12
13
# File 'lib/template.rb', line 11

def file_name
  @file_name
end

Instance Method Details

#closeObject



26
27
28
# File 'lib/template.rb', line 26

def close
  @file.close
end

#insert(img_attrs) ⇒ Object

Writes data row to file



22
23
24
# File 'lib/template.rb', line 22

def insert(img_attrs)
  @file.puts(img_attrs.join(','))
end