lib/picky/sources/csv.rb in picky-1.3.0 vs lib/picky/sources/csv.rb in picky-1.3.1

- old
+ new

@@ -24,22 +24,25 @@ # attr_reader :file_name # The options that were passed into #new. # - attr_reader :csv_options + attr_reader :csv_options, :key_format # The data category names. # attr_reader :category_names def initialize *category_names, options require 'csv' @category_names = category_names - @csv_options = Hash === options && options || {} - @file_name = @csv_options.delete(:file) || raise_no_file_given(category_names) + @csv_options = Hash === options && options || {} + @file_name = @csv_options.delete(:file) || raise_no_file_given(category_names) + + key_format = options.delete :key_format + @key_format = key_format && key_format.to_sym || :to_i end # Raises a NoCSVFileGiven exception. # def raise_no_file_given category_names # :nodoc: @@ -49,10 +52,10 @@ # Harvests the data to index. # def harvest _, category index = category_names.index category.from get_data do |ary| - indexed_id = ary.shift.to_i # TODO is to_i necessary? + indexed_id = ary.shift text = ary[index] next unless text text.force_encoding 'utf-8' # TODO Still needed? yield indexed_id, text end \ No newline at end of file