Module: Linkage::Helpers::CSV
- Included in:
- MatchSets::CSV, ScoreSets::CSV
- Defined in:
- lib/linkage/helpers/csv.rb
Instance Method Summary collapse
- #csv_filename(options) ⇒ Object
- #open_csv_for_reading(options) ⇒ Object
- #open_csv_for_writing(options) ⇒ Object
Instance Method Details
#csv_filename(options) ⇒ Object
4 5 6 |
# File 'lib/linkage/helpers/csv.rb', line 4 def csv_filename() File.([:filename], [:dir] || '.') end |
#open_csv_for_reading(options) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/linkage/helpers/csv.rb', line 8 def open_csv_for_reading() filename = csv_filename() if !File.exist?(filename) raise MissingError, "#{filename} does not exist" end ::CSV.open(filename, 'rb', :headers => true) end |
#open_csv_for_writing(options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/linkage/helpers/csv.rb', line 16 def open_csv_for_writing() filename = csv_filename() if ![:overwrite] && File.exist?(filename) raise ExistsError, "#{filename} exists and not in overwrite mode" end if [:dir] FileUtils.mkdir_p(File.dirname(filename)) end ::CSV.open(filename, 'wb') end |