Module: CsvMadness::SheetMethods::FileMethods

Included in:
CsvMadness::Sheet
Defined in:
lib/csv_madness/sheet_methods/file_methods.rb

Instance Method Summary collapse

Instance Method Details

#reload_spreadsheet(opts = @opts) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/csv_madness/sheet_methods/file_methods.rb', line 30

def reload_spreadsheet( opts = @opts )
  load_csv if @spreadsheet_file
  set_initial_columns( opts[:columns] )
  create_record_class
  package

  set_index_columns( opts[:index] )
  reindex
end

#save(file = self.spreadsheet_file) ⇒ Object

pass an arbitrary filepath to save sheet to that filepath call save() with no arguments to overwrite the current spreadsheet file call save(:timestamp) to make a timestamped copy of the spreadsheet file

Obviously, the last two require self.spreadsheet_file to exist and be writable



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/csv_madness/sheet_methods/file_methods.rb', line 13

def save( file = self.spreadsheet_file )
  if file == :timestamp
    if self.spreadsheet_file
      file = self.spreadsheet_file.fwf_filepath.timestamp
    else
      raise ArgumentError.new( "CsvMadness.save(:timestamp) - Spreadsheet must be specified by @spreadsheet_file" )
    end
  end

  if file
    self.write_to_file( file )
  else
    raise "CsvMadness.save(:timestamp) - Spreadsheet must be specified by spreadsheet_file"
  end
end

#write_to_file(file) ⇒ Object



4
5
6
# File 'lib/csv_madness/sheet_methods/file_methods.rb', line 4

def write_to_file( file )
  self.class.write_to_file( self, file )
end