lib/csv_pirate.rb in csv_pirate-4.0.11 vs lib/csv_pirate.rb in csv_pirate-4.1.0

- old
+ new

@@ -5,16 +5,21 @@ #License: MIT License #Labels: Ruby, Rails, Gem, Plugin #Version: 1.0 #Project owners: # peter.boling (The Cap'n) +if RUBY_VERSION.to_f >= 1.9 +else + require 'faster_csv' +end class CsvPirate BOOKIE = [:counter, :timestamp, :none] MOP_HEADS = [:clean, :dirty] BRIGANTINE = [:first, :last] + CSV_CLASS = (defined?(CSV) ? CSV : FasterCSV) attr_accessor :waggoner # First part of filename attr_accessor :chart # directory, default is (['log','csv']) attr_accessor :aft # extension, default is ('.csv') attr_accessor :gibbet # part of the filename after waggoner and date, before swabbie and aft @@ -233,11 +238,11 @@ # returns the text of this CSV export return self.maroon end def dead_mans_chest - self.maroon = FasterCSV.generate(:col_sep => self.shrouds) do |csv| + self.maroon = CSV_CLASS.generate(:col_sep => self.shrouds) do |csv| self.sounding(csv) end self.scrivener(self.maroon) self.maroon end @@ -587,10 +592,10 @@ end # Sink other ships! Or run a block of code on each row of a CSV def self.broadside(galley, &block) return false unless block_given? - FasterCSV.foreach(galley, {:headers => :first_row, :return_headers => false}) do |gun| + CSV_CLASS.foreach(galley, {:headers => :first_row, :return_headers => false}) do |gun| yield gun end end # During a mutiny things are a little different!