11 Oct '12, 1pm

Object-Oriented file importing and parsing

October 11, 2012 Comments (View) Object-Oriented file importing and parsing The following is an example of file importing and parsing in Ruby using object-oriented techniques such as duck typing and dependency injection . Inject a CSVParser dependency into a the Importer # app/controllers/contact_imports_controller.rb: class ContactImportsController < ApplicationController def new @importer = Importer.new end def create @importer = Importer.new( parser: CSVParser.new(import_file), import_type: import_type ) @importer.import respond_with(@importer, location: contacts_path) end private def import_file params[:importer][:file] end def import_type params[:importer][:import_type] end end A given parser must respond to rows and an instance of the given import_type must respond to create # app/models/importer.rb class Importer include ActiveModel::Validations include ActiveModel:...

Full article: http://robots.thoughtbot.com/post/33362333571/object-orie...

Tweets

Unintentional file creation caused by inserting...

ruby-lang.org 12 Oct '12, 12pm

Unintentional file creation caused by inserting a illegal NUL character A vulnerability was found that file creation routi...

[at]include hoge が +hogeで展開できるのか。.sassいいな。惰性的に....

sass-lang.com 14 Oct '12, 9am

Whether an error in the Sass code should cause Sass to provide a detailed description within the generated CSS file. If se...

#WikiLeaks case file access eyed by court

militarytimes.com 10 Oct '12, 8pm

http://www.militarytimes.com/news/2012/10/ap-wikileaks-court-file-access-101012/ WikiLeaks case file access eyed by court ...