Permalink
Browse files

Added ability to pass options to map_fields call (Currently to pass C…

…SV encoding)
  • Loading branch information...
1 parent 6a033d7 commit 1f6d90e98aa5707829eefb59853133eecc4bb4dc @andrewtimberlake andrewtimberlake committed Mar 26, 2012
Showing with 5 additions and 4 deletions.
  1. +2 −2 lib/map_fields/controller.rb
  2. +3 −2 lib/map_fields/mapper.rb
@@ -2,9 +2,9 @@
module MapFields
module Controller
- def map_fields(fields, file, &block)
+ def map_fields(fields, file, options={}, &block)
append_view_path File.expand_path('../../../views/', __FILE__)
- @mapper = Mapper.new(self, fields, file)
+ @mapper = Mapper.new(self, fields, file, options)
if @mapper.mapped?
block.call(@mapper)
else
View
@@ -7,11 +7,12 @@ module MapFields
class MissingFileError < StandardError; end
class Mapper
- def initialize(controller, fields, file)
+ def initialize(controller, fields, file, options={})
@controller = controller
params = controller.params
@fields = get_fields(controller, fields)
@params = ParamsParser.parse(params)
+ @options = options
if file
file = save_file controller, file
@@ -89,7 +90,7 @@ def save_file(controller, file)
def parse_first_few_lines(file)
rows = []
rowcount = 0
- CSV.foreach(file) do |row|
+ CSV.foreach(file, encoding: @options[:encoding] || 'UTF-8') do |row|
rows << row
break if (rowcount += 1) >= 10
end

0 comments on commit 1f6d90e

Please sign in to comment.