Class: FileWriter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileWriter

Returns a new instance of FileWriter.



7
8
9
# File 'lib/prefixtree/tocsv.rb', line 7

def initialize
  @path = 'lib/data.csv'
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/prefixtree/tocsv.rb', line 5

def path
  @path
end

Instance Method Details

#read_from_csvObject



18
19
20
# File 'lib/prefixtree/tocsv.rb', line 18

def read_from_csv
  CSV.read(path).to_a
end

#save_to_csv(word_list) ⇒ Object



11
12
13
14
15
16
# File 'lib/prefixtree/tocsv.rb', line 11

def save_to_csv(word_list)
  CSV.open(path, 'a') do |csv|
    csv << word_list
  end
  puts 'Successfully added to CSV'
end