Class: Csv
- Inherits:
-
Object
- Object
- Csv
- Defined in:
- lib/csv_controller.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize ⇒ Csv
constructor
A new instance of Csv.
- #read_from_csv ⇒ Object
- #save_to_csv(word_list) ⇒ Object
Constructor Details
#initialize ⇒ Csv
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
#path ⇒ Object
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_csv ⇒ Object
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 |