Module: BBMB::Util::TransferDat

Defined in:
lib/bbmb/util/transfer_dat.rb

Class Method Summary collapse

Class Method Details

.parse(io) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/bbmb/util/transfer_dat.rb', line 9

def TransferDat.parse(io)
  io.rewind
  data = io.read
  data.split(/[\r\n]+/).collect { |line|
    if(parsed = parse_line(line))
      yield parsed
    end
  }
end

.parse_line(line) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bbmb/util/transfer_dat.rb', line 18

def TransferDat.parse_line(line)
  begin
    result = Model::Order::Info.new
    result.pcode  = line[13,7].to_i.to_s
    result.description = line[20,50].strip
    result.ean13 = line[74,13]
    result.quantity = line[70,4].to_i
    result
  rescue Exception => e
    SBSM.info('transfer') {
      [e.class, e.message, e.backtrace].pretty_inspect
    }
  end
end