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