Created
December 11, 2012 16:55
-
-
Save mikecmpbll/4260251 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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