Skip to content

Instantly share code, notes, and snippets.

@mikecmpbll
Created December 11, 2012 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikecmpbll/4260251 to your computer and use it in GitHub Desktop.
Save mikecmpbll/4260251 to your computer and use it in GitHub Desktop.
4 def import
5 unless params[:file].blank?
6 labels = Array.new
7 IO.foreach( params[:file].tempfile ) do |line|
8 if /;/.match( line )
9 labels << line.split( ';' )
10 elsif /,/.match( line )
11 labels << line.split( ',' )
12 else
13 labels << line
14 end
15 end
16 labels.flatten! # flatten out inner arrays
17 labels.uniq! # only unique
18 labels.reject! { |x| x.blank? } # no blank
19 labels.map! { |x| x.strip } # remove whitespace
20
21 # get current labels
22 cur_labels = Label.select( 'name' ).map { |row| row.name }
23 @duplicates = labels & cur_labels
24 @new = labels - cur_labels
25 puts @new.inspect
26 #@new.each do |label|
27 # Label.create!( name: label )
28 #end
29 end
30 end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment