Class: Csv

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCsv

Returns a new instance of Csv.



7
8
9
# File 'lib/csv_controller.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/csv_controller.rb', line 5

def path
  @path
end

Instance Method Details

#read_from_csvObject



19
20
21
# File 'lib/csv_controller.rb', line 19

def read_from_csv
  CSV.parse(File.read(@path), converters: :all)
end

#save_to_csv(word_list) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/csv_controller.rb', line 11

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