|
@ -9,7 +9,7 @@ class BikeCsvImporter |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def run |
|
|
def run |
|
|
result = {imported_count: 0, skipped_errors: {}} |
|
|
result = {imported: {}, skipped: {}} |
|
|
|
|
|
|
|
|
@bike_purpose_cache = {} |
|
|
@bike_purpose_cache = {} |
|
|
@bike_brand_cache = {} |
|
|
@bike_brand_cache = {} |
|
@ -19,9 +19,9 @@ class BikeCsvImporter |
|
|
bike = import_bike bike_hash |
|
|
bike = import_bike bike_hash |
|
|
check_method = dry_run ? :valid? : :persisted? |
|
|
check_method = dry_run ? :valid? : :persisted? |
|
|
if bike.try check_method |
|
|
if bike.try check_method |
|
|
result[:imported_count] += 1 |
|
|
result[:imported][bike.shop_id] = bike.inspect |
|
|
else |
|
|
else |
|
|
result[:skipped_errors][bike.try(:shop_id) || bike_hash.values.first] = bike.try(:errors).try(:messages) |
|
|
result[:skipped][bike.try(:shop_id) || bike_hash.values.first] = bike.try(:errors).try(:messages) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
@ -144,7 +144,8 @@ class BikeCsvImporter |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def bike_attr_model(bike_hash) |
|
|
def bike_attr_model(bike_hash) |
|
|
clean_value bike_hash['model'] |
|
|
model = clean_value bike_hash['model'] |
|
|
|
|
|
model unless model =~ /unknown/i |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def clean_value(value) |
|
|
def clean_value(value) |
|
|