Skip to content

Instantly share code, notes, and snippets.

@criess
Created February 14, 2019 12:49
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 criess/6bca63b42658957040953dd5d28db467 to your computer and use it in GitHub Desktop.
Save criess/6bca63b42658957040953dd5d28db467 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
BuyingProfile.new
Address.new
data = YAML.load_file('imports.yml')
import = Import.create!(source: 'CUSTOM/CR/201902', import_start_at: Time.current)
data[:addresses].each do |a|
next if a.nil?
address = Address.new(**a.attributes.symbolize_keys)
!address.valid? && (address.country = 'us')
address.save
end
data[:people].each do |p|
next if p.nil?
person = Person.new(**p.attributes.symbolize_keys)
person.import = import
background_codes = data[:people_investment_backgrounds][person.id]
person.investment_backgrounds = InvestmentBackground.where(code: background_codes).to_a
person.save
end
data[:companies].each do |c|
next if c.nil?
company = Company.new(**c.attributes.symbolize_keys)
company.import = import
background_codes = data[:companies_investment_backgrounds][company.id]
company.investment_backgrounds = InvestmentBackground.where(code: background_codes).to_a
company.save
end
data[:bp].each do |b|
bprof = BuyingProfile.new(**b.attributes.symbolize_keys)
bprof.import = import
industry_ids = data[:bp_industries][bprof.id]
bprof.industries = Industry.where(id: industry_ids).to_a
region_ids = data[:bp_regions][bprof.id]
bprof.regions = Region.where(id: region_ids).to_a
person_ids = data[:bp_people][bprof.id]
bprof.people = Person.where(id: person_ids).to_a
transaction_type_codes = data[:bp_transaction_types][bprof.id]
bprof.transaction_types = TransactionType.where(code: transaction_type_codes).to_a
bprof.save
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment