Class: Lane::Report

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

Instance Method Summary collapse

Constructor Details

#initialize(path, separator = ',') ⇒ Report

Returns a new instance of Report.



5
6
7
8
9
# File 'lib/Lane/report.rb', line 5

def initialize(path, separator = ',')
  # instance variables
  @path = path
  @separator = separator
end

Instance Method Details

#append_data(data) ⇒ Object



28
29
30
31
# File 'lib/Lane/report.rb', line 28

def append_data(data)
  # method that appends one piece of data and a separator
  File.write(@path, "#{data}#{@separator} ", mode: 'a')
end

#append_empty_columns(columns) ⇒ Object



39
40
41
42
43
44
# File 'lib/Lane/report.rb', line 39

def append_empty_columns(columns)
  # Inserts the passed number of empty columns for cases of missing info
  columns.times do
    File.write(@path, @separator.to_s, mode: 'a')
  end
end

#append_line(line) ⇒ Object



11
12
13
14
# File 'lib/Lane/report.rb', line 11

def append_line(line)
  # method that appends a line to a report.
  File.write(@path, line, mode: 'a')
end

#clearObject



20
21
22
# File 'lib/Lane/report.rb', line 20

def clear
  File.write(@path, '', mode: 'w')
end

#deleteObject



24
25
26
# File 'lib/Lane/report.rb', line 24

def delete
  File.delete(@path)
end

#new_lineObject



33
34
35
36
37
# File 'lib/Lane/report.rb', line 33

def new_line
  # Deletes the last separator and then inserts a new line
  File.truncate(@path, File.size(@path) - 2)
  File.write(@path, "\n", mode: 'a')
end

#write_header(header) ⇒ Object



16
17
18
# File 'lib/Lane/report.rb', line 16

def write_header(header)
  File.write(@path, "#{header}\n", mode: 'w')
end