Skip to content

Instantly share code, notes, and snippets.

@nathancolgate
Created March 22, 2019 19:33
Show Gist options
  • Save nathancolgate/20fb3b87a2375495360b96374fea25f0 to your computer and use it in GitHub Desktop.
Save nathancolgate/20fb3b87a2375495360b96374fea25f0 to your computer and use it in GitHub Desktop.
A ruby script for parsing the OmniClass excel file.
require 'roo'
require 'pp'
xlsx = Roo::Excelx.new('./omni.xlsx')
# sheet = xlsx.default_sheet
ones = []
twos = []
threes = []
fours = []
current_one = ""
current_two = ""
current_three = ""
current_four = ""
xlsx.each do |row|
n = {}
n[:attributes] = {}
n[:identifier] = row[0]
if row[1] # ones
current_one = row[0]
n[:attributes][:name] = row[1]
n[:attributes][:description] = row[5]
ones << n
elsif row[2]
current_two = row[0]
n[:attributes][:name] = row[2]
n[:attributes][:description] = row[5]
n[:parent] = "XXXConsumerClassification.find_by(identifier: \"#{current_one}\")XXX"
twos << n
elsif row[3]
current_three = row[0]
n[:attributes][:name] = row[3]
n[:attributes][:description] = row[5]
n[:parent] = "XXXConsumerClassification.find_by(identifier: \"#{current_two}\")XXX"
threes << n
elsif row[4]
current_four = row[0]
n[:attributes][:name] = row[4]
n[:attributes][:description] = row[5]
n[:parent] = "XXXConsumerClassification.find_by(identifier: \"#{current_three}\")XXX"
fours << n
end
end
pp fours
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment