Created
July 28, 2009 11:43
-
-
Save hojberg/157168 to your computer and use it in GitHub Desktop.
This file contains 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
# Delete duplicates | |
rows = [] | |
res.each do |row| | |
# skip if already saved in new array | |
next if rows.detect { |r| r[3] == row[3] } | |
# Find multiple instances sale | |
rows_with_same_sale_id = res.select { |r| r[3] == row[3] } | |
# create an array with only the markers ie. ["I", "N", "E"] | |
same_sale_id_markers = rows_with_same_sale_id.map(&:first) | |
# Add I or N using I < N | |
if same_sale_id_markers.include?("I") && !same_sale_id_markers.include?("N") | |
rows << rows_with_same_sale_id.detect { |r| r.first == "I" } | |
elsif same_sale_id_markers.include?("N") | |
rows << rows_with_same_sale_id.detect { |r| r.first == "N" } | |
end | |
# Add E, D or C using E < (D,C) | |
if same_sale_id_markers.include?("E") && (!same_sale_id_markers.include?("D") || !same_sale_id_markers.include?("C")) | |
rows << rows_with_same_sale_id.detect { |r| r.first == "E" } | |
elsif same_sale_id_markers.include?("D") || same_sale_id_markers.include?("C") | |
rows << rows_with_same_sale_id.detect { |r| r.first == "D" } if same_sale_id_markers.include?("D") | |
rows << rows_with_same_sale_id.detect { |r| r.first == "C" } if same_sale_id_markers.include?("C") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment