From 0ca60f53a6c2d3cedf8a19a5ea063c42c29a93e5 Mon Sep 17 00:00:00 2001 From: viehlieb Date: Fri, 20 Jan 2023 14:09:47 +0100 Subject: [PATCH] gehirnpups --- lib/foodsoft_article_import/borkenstein.rb | 95 +++++++++++----------- 1 file changed, 46 insertions(+), 49 deletions(-) diff --git a/lib/foodsoft_article_import/borkenstein.rb b/lib/foodsoft_article_import/borkenstein.rb index c0f99dd..237e4e2 100644 --- a/lib/foodsoft_article_import/borkenstein.rb +++ b/lib/foodsoft_article_import/borkenstein.rb @@ -35,59 +35,56 @@ module FoodsoftArticleImport # check if the line is empty next if row[1].blank? || row[1] == "-" - # Split string and remove beginning " - matched = row[2].gsub(/^\"/, "").gsub(/\"$/, "").match(REGEX[:main]) + # Split string and remove beginning " + matched = row[2].gsub(/^\"/, "").gsub(/\"$/, "").match(REGEX[:main]) - next if matched.nil? + next if matched.nil? - name, units, price_high, price_low = matched.captures + name, units, price_high, price_low = matched.captures - # Try to get origin - matched_name = name.match(REGEX[:origin]) - if matched_name - name, origin = matched_name.captures - else - name, origin = name.gsub(/\s{2,}/, ""), nil - end - - # Manufacturer - if name.match(/^[A-Za-z]{2,3}\s{1}/) - name.gsub!(/^[A-Za-z]{2,3}\s{1}/, "") - manufacturer = global_manufacturer - end - - - # Get unit quantities - units = units.split("x") - if units.size == 2 - unit_quantity = units.first - unit = units.last - else - unit_quantity = 1 - unit = units.first - end - - article = { - :number => row[1], - :name => name, - :origin => origin, - :manufacturer => manufacturer, - :unit_quantity => unit_quantity, - :unit => unit, - :price => price_low, # Inklusive Rabattstufe von 10% - :tax => 0.0 # Tax is included - } - - # test, if neccecary attributes exists - if article[:unit].nil? || article[:price].nil? || article[:unit_quantity].nil? - raise "Fehler: Einheit, Preis und MwSt. müssen gegeben sein: #{article.inspect}" - end - - yield article, nil, i - end + # Try to get origin + matched_name = name.match(REGEX[:origin]) + if matched_name + name, origin = matched_name.captures + else + name, origin = name.gsub(/\s{2,}/, ""), nil end + + # Manufacturer + if name.match(/^[A-Za-z]{2,3}\s{1}/) + name.gsub!(/^[A-Za-z]{2,3}\s{1}/, "") + manufacturer = global_manufacturer + end + + + # Get unit quantities + units = units.split("x") + if units.size == 2 + unit_quantity = units.first + unit = units.last + else + unit_quantity = 1 + unit = units.first + end + + article = { + :number => row[1], + :name => name, + :origin => origin, + :manufacturer => manufacturer, + :unit_quantity => unit_quantity, + :unit => unit, + :price => price_low, # Inklusive Rabattstufe von 10% + :tax => 0.0 # Tax is included + } + + # test, if neccecary attributes exists + if article[:unit].nil? || article[:price].nil? || article[:unit_quantity].nil? + raise "Fehler: Einheit, Preis und MwSt. müssen gegeben sein: #{article.inspect}" + end + + yield article, nil, i end end - end -end \ No newline at end of file +end