Skip to content

Instantly share code, notes, and snippets.

@beaugaines
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save beaugaines/28cc7c252378db6032a6 to your computer and use it in GitHub Desktop.

Select an option

Save beaugaines/28cc7c252378db6032a6 to your computer and use it in GitHub Desktop.
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
data = row.to_hash
Plan.create(title: data['Title'])
steps = data['Steps'].split(/\d/).reject(&:empty?)
steps.map! { |s| s.gsub(/^\.\s+/, '') }
.map! { |s| s.gsub(/\n|:/, '') }
.map! { |s| s.split(/Expected Result/) }
.each { |s| Step.create(description: s[0], result: s[1]) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment