Skip to content

Instantly share code, notes, and snippets.

@kirel
Created July 10, 2012 13:34
Show Gist options
  • Select an option

  • Save kirel/3083270 to your computer and use it in GitHub Desktop.

Select an option

Save kirel/3083270 to your computer and use it in GitHub Desktop.
module CSVMappings; ... end
module NavisionFtpsConnection; ... end
class CSVImporter
include ...
def initialize(file, clear, sep, etc...)
@file = file, ...
end
def import
prepare_import
iterate_rows do |row|
import_row(row)
end
end
protected
def prepare_import
OptionType Gedöns
clear if @clear
end
def interate_rows
CSV.foreach @file, ... { |row| yield row }
end
def import_row
raise 'abstract'
end
end
class InitialImporter
def initialize file, ...
super file, ...
end
def import_row row
...
end
end
class NavisionImporter
include ...
def initialize file, ...
super file, ...
end
def import_row row
case row_type(row)
when :article
...
when :price
...
when :image
...
end
end
end
# Usage NavisionImporter.new(file).import
@tilt

tilt commented Jul 10, 2012

Copy link
Copy Markdown

Ja, das sieht schön aus.

Ich weiß auch nicht warum ich mich gescheut habe, das Modul mal zur Klasse zu befördern... Dass der Importer Zustände hat war mir nicht mehr aufgefallen, nachdem alles über Funktionsparameter lief.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment