Ich habe ein Problem mit dieser Zeile File.foreach ('ojo.txt'). with_object ([]) do | line, result |
Zeile für Zeile einer Datei gehen, weil ich es brauche, um die ersten drei Zeichen einer Datei Bestellung zu entschlüsseln. mein Problem ist, zum Zeitpunkt der Speicherung des folgenden und ich in diesem Zyklus bin do
ich leer Aufzeichnungen speichert ... und eine Zeit, in dem analyises kommt, dass Beispiel:Probleme beim Analysieren und Speichern von Dateien in Ruby
LIN00000100635818000159EN
IMDF CU VINO S EMA 14.5G CATAL PREM BOT 75
QTY 21000000000000001SIN
QTY129000000000000001SIN
MOA203000000000016338.00
PRIAAA000000021498.00LIUSIN
ALCA DE1
PCD 10000024.00
MOA204000000000005160.00
ALCC CA1
MOA 23000000000000180.00
das sind die Linien Verwendung if line.start_with? ('LIN')
zu analysieren und dann dekodieren. aber diese sechs 11 Zeilen möchte ich zusammen analysieren, weil in einer Datei X die Menge der Produkte in wenigen Wörtern viele Male wiederholt wird. So wie ich es mache, hält mich nur der erste Artikel, die anderen nicht.
zusätzlich möchte ich, wenn möglich, einen Bericht mit einem Datensatz und dem Detail dieses Datensatzes auf eine etwas einfache Art erzeugen. Ich bin neu in Ruby.
Ich füge meinen Code an und sehe, könntest du mir helfen.
File.foreach('ojo.txt').with_object([]) do |line, result|
if lines.start_with?('LIN')
@cproducto = lines[8..-2]
end
if lines.start_with?('IMD')
@desproducto = lines[8..-1]
end
if lines.start_with?('QTY 21')
@cantidadpedida = lines[-5..-4]
caja = lines[-3..-1]
if caja = ('CSC')
@tcaja = 'cajas de carton'
end
if pedido = ('CS')
@tcaja= 'cajas'
end
if pedido = ('SIN')
@tcaja= 'Uunidades Simples'
end
if pedido = ('KGM')
@tcaja= 'Kilogramos'
end
end
if lines.start_with?('QTY129')
@cantidadunidades = lines[-6..-4]
@tunidad = 'Unidades Simples'
end
if lines.start_with?('MOA 203')
@precio = 'Precio neto'
@precioneto = lines[-10..-1]
end
if lines.start_with?('MOA 23')
@tcargo = 'Cargo'
@valorcargo = lines[-10..-1]
end
if lines.start_with?('MOA 203')
@precio = 'Precio neto'
@precioneto = lines[-10..-1]
end
if lines.start_with?('MOA 204')
@tdescu = 'Descuento'
@valordescu = lines[-10..-1]
end
if lines.start_with?('PRIAAA')
pedido = lines[-3..-1]
@valorcd = lines[-16..-8]
if pedido = ('CSC')
@tcaja2 = 'cajas de carton'
end
if pedido = 'CS'
@tcaja2 = 'cajas'
end
end
if lines.start_with?('ALCA') and (lines.include?('DE1') or lines.include?('DE2'))
@cdescuento = 'DESCUENTO'
end
if lines.start_with?('ALCC') and (lines.include?('CA1') or lines.include?('CA1'))
@ccargo = 'CARGO'
end
if lines.start_with?('PCD') and (lines[5] = '1')
porcentaje = lines[-6..-1]
@porecentaje = 'porcentaje de descuento'
else
@porecentaje = 'porcentaje del cargo'
end
if lines.start_with?('MOA 86')
clave = lines[0..2]
importe = lines[-9..-1]
end
if lines.start_with?('CNT')
@items2 = lines[-2..-1]
end
end
Detalles2s.create(descrip: @desproducto, tipebox: @tcaja , cantidad: @cantidadunidades, tipounidad: @tunidad , precio: @precio, precioneto: @precioneto)
so etwas um die Linien zu analysieren, aber das nicht
if line.start_with?('LIN') and not line.start_with?('IMD') and lines.start_with?('QTY 21') and lines.start_with?('QTY129') and lines.start_with?('MOA 203') and (lines.start_with?('MOA 204') or lines.start_with?('MOA 23')) and lines.start_with?('PRIA') and lines.start_with?('PCD') and (lines.start_with?('ALCA') or lines.start_with?('ALCC'))
Als ersten Schritt führen Rubin mit dem '-w' Option, und korrigieren Sie alle' Warnung: gefunden = bedingte, sollte '== werden. – BernardK