gehirnpups
This commit is contained in:
parent
0ca60f53a6
commit
7a058847eb
3 changed files with 67 additions and 50 deletions
|
@ -52,10 +52,14 @@ module FoodsoftArticleImport
|
||||||
# (sub)categories are in first two content cells - assume if there's a price it's a product
|
# (sub)categories are in first two content cells - assume if there's a price it's a product
|
||||||
if row[:number].blank? && row[:unit_price].blank?
|
if row[:number].blank? && row[:unit_price].blank?
|
||||||
category = row[:name]
|
category = row[:name]
|
||||||
|
yield nil, nil, linenum
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
# skip products without a number
|
# skip products without a number
|
||||||
row[:number].blank? and next
|
if row[:number].blank?
|
||||||
|
yield nil, nil, linenum
|
||||||
|
next
|
||||||
|
end
|
||||||
# extract name and unit
|
# extract name and unit
|
||||||
errors = []
|
errors = []
|
||||||
notes = []
|
notes = []
|
||||||
|
@ -67,7 +71,10 @@ module FoodsoftArticleImport
|
||||||
manufacturer = nil
|
manufacturer = nil
|
||||||
prod_category = nil
|
prod_category = nil
|
||||||
RES_PARSE_UNIT.each do |re|
|
RES_PARSE_UNIT.each do |re|
|
||||||
m=name.match(re) or next
|
m=name.match(re)
|
||||||
|
unless m
|
||||||
|
yield nil, nil, linenum
|
||||||
|
end
|
||||||
unit = self.normalize_unit(m[3])
|
unit = self.normalize_unit(m[3])
|
||||||
name = name.sub(re, '').sub(/\(\s*\)\s*$/,'').sub(/\s+/, ' ').sub(/\.\s*$/, '').strip
|
name = name.sub(re, '').sub(/\(\s*\)\s*$/,'').sub(/\s+/, ' ').sub(/\.\s*$/, '').strip
|
||||||
break
|
break
|
||||||
|
|
|
@ -33,13 +33,15 @@ module FoodsoftArticleImport
|
||||||
end
|
end
|
||||||
|
|
||||||
# check if the line is empty
|
# check if the line is empty
|
||||||
next if row[1].blank? || row[1] == "-"
|
unless row[1].blank? || row[1] == "-"
|
||||||
|
|
||||||
# Split string and remove beginning "
|
# Split string and remove beginning "
|
||||||
matched = row[2].gsub(/^\"/, "").gsub(/\"$/, "").match(REGEX[:main])
|
matched = row[2].gsub(/^\"/, "").gsub(/\"$/, "").match(REGEX[:main])
|
||||||
|
|
||||||
next if matched.nil?
|
if matched.nil?
|
||||||
|
puts "No regular article data for #{row[1]}: #{row[2]}"
|
||||||
|
yield nil, nil, nil
|
||||||
|
else
|
||||||
name, units, price_high, price_low = matched.captures
|
name, units, price_high, price_low = matched.captures
|
||||||
|
|
||||||
# Try to get origin
|
# Try to get origin
|
||||||
|
@ -86,5 +88,9 @@ module FoodsoftArticleImport
|
||||||
yield article, nil, i
|
yield article, nil, i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
yield nil, nil, i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -25,10 +25,14 @@ module FoodsoftArticleImport::Foodsoft
|
||||||
# skip first header row
|
# skip first header row
|
||||||
if header_row
|
if header_row
|
||||||
header_row = false
|
header_row = false
|
||||||
|
yield nil, nil, i
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
# skip empty lines
|
# skip empty lines
|
||||||
next if row[2].blank?
|
if row[2].blank?
|
||||||
|
yield nil, nil, i
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
article = {:number => row[1],
|
article = {:number => row[1],
|
||||||
:name => row[2],
|
:name => row[2],
|
||||||
|
|
Loading…
Add table
Reference in a new issue