Class: Cards::CsvBuilder

Inherits:
Object show all
Defined in:
lib/cards/csv_builder.rb

Direct Known Subclasses

MasterStoryList, TrackerCsv

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ CsvBuilder

Returns a new instance of CsvBuilder.



3
4
5
6
7
8
# File 'lib/cards/csv_builder.rb', line 3

def initialize(file_name)
  @file_name = file_name
  @file = File.open(file_name, "wb")
  @csv = CSV::Writer.create(@file)
  @csv << header
end

Class Method Details

.from(parser) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/cards/csv_builder.rb', line 14

def self.from(parser)
  builder = self.new(parser.default_output_file + ".#{self.to_s.gsub("Cards::", "").downcase}.csv")

  parser.each_row do |row|
    builder.process(row)
  end

  builder.done
end

Instance Method Details

#add_activity(name, params = {}) ⇒ Object



30
31
32
# File 'lib/cards/csv_builder.rb', line 30

def add_activity(name, params = {})
  @activity = name
end

#add_story(name, params = {}) ⇒ Object



38
39
40
# File 'lib/cards/csv_builder.rb', line 38

def add_story(name, params = {})
  raise "implement me"
end

#add_task(name, params = {}) ⇒ Object



34
35
36
# File 'lib/cards/csv_builder.rb', line 34

def add_task(name, params = {})
  @task = name
end

#doneObject



42
43
44
45
46
# File 'lib/cards/csv_builder.rb', line 42

def done
  @csv.close
  @file.close
  `open #{@file_name.gsub(' ', '\\ ')}`
end

#headerObject



10
11
12
# File 'lib/cards/csv_builder.rb', line 10

def header
  raise "implement me"
end

#process(row) ⇒ Object



24
25
26
27
28
# File 'lib/cards/csv_builder.rb', line 24

def process(row)
  [:activity, :task, :story].each do |handler|
    send("add_#{handler}", row[handler], row) if row[handler]
  end
end