Skip to content

Instantly share code, notes, and snippets.

@MikeSilvis
Last active December 10, 2015 17:29
Show Gist options
  • Save MikeSilvis/4468438 to your computer and use it in GitHub Desktop.
Save MikeSilvis/4468438 to your computer and use it in GitHub Desktop.
require 'yaml'
class CreateCars
class << self
def normalize_makes
makes.collect do |make|
{ name: make["Make"], id: make["Make_ID"] }
end
end
def normalize_models
normalized = []
models.each do |model|
normalized << { name: model["Model"], make_id: model["Make_ID"] } if valid_type_and_make? model
end
normalized
end
def valid_type_and_make?(model)
(model["Type_ID"] == 1) && (make_ids.include?(model["Make_ID"]))
end
def make_ids
normalize_makes.map { |make| make[:id] }
end
def makes
YAML::load(File.open(File.expand_path("../../../lib/assets/vehicles/Vehicle_Make.yml", __FILE__)))
end
def models
YAML::load(File.open(File.expand_path("../../../lib/assets/vehicles/Vehicle_Model.yml", __FILE__)))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment