Skip to content

Commit

Permalink
Fix bug zurrose price format
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasuhiro Asaka committed Jul 9, 2013
1 parent 286c6cb commit e4f3e5e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/oddb2xml/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,17 @@ def to_arry
end
class ZurroseExtractor < Extractor
def initialize(dat)
@io = StringIO.new(dat)
@io = StringIO.new(dat) if dat
end
def to_hash
data = {}
while line = @io.gets
next unless line =~ /(7680\d{9})(\d{1})\r\n$/
data[$1.to_s] = {
:vat => $2.to_s,
:price => sprintf("%.2f", line[60,6].gsub(/(\d{2})$/, "." + $1.to_s).to_f)
:price => sprintf("%.2f", line[60,6].gsub(/(\d{2})$/, '.\1').to_f)
}
end
end if @io
data
end
end
Expand Down
43 changes: 43 additions & 0 deletions spec/extractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,46 @@
describe Oddb2xml::Extractor do
it "pending"
end

describe Oddb2xml::ZurroseExtractor do
context 'when transfer.dat is empty' do
subject { Oddb2xml::ZurroseExtractor.new("") }
it { expect(subject.to_hash).to be_empty }
end
context 'when transfer.dat is nil' do
subject { Oddb2xml::ZurroseExtractor.new(nil) }
it { expect(subject.to_hash).to be_empty }
end
context 'when as line break mark \n is given' do
subject do
dat = <<-DAT
1120020244FERRO-GRADUMET Depottabl 30 Stk 000895001090300C060710076803164401152
DAT
Oddb2xml::ZurroseExtractor.new(dat)
end
it { expect(subject.to_hash).to be_empty }
end
context 'when only 1 record have a valid EAN code' do
subject do
dat = <<-DAT
1120020209ERYTRHOCIN I.V. Trockensub Fl 1g 001518002010300B080160000000000000002\r\n
1120020244FERRO-GRADUMET Depottabl 30 Stk 000895001090300C060710076803164401152\r\n
DAT
Oddb2xml::ZurroseExtractor.new(dat)
end
it { expect(subject.to_hash.keys.length).to eq(1) }
it { expect(subject.to_hash.keys.first).to eq("7680316440115") }
end
context 'when expected line is given' do
subject do
dat = <<-DAT
1120020244FERRO-GRADUMET Depottabl 30 Stk 000895001090300C060710076803164401152\r\n
DAT
Oddb2xml::ZurroseExtractor.new(dat)
end
it { expect(subject.to_hash.keys.length).to eq(1) }
it { expect(subject.to_hash.keys.first).to eq("7680316440115") }
it { expect(subject.to_hash.values.first[:vat]).to eq("2") }
it { expect(subject.to_hash.values.first[:price]).to eq("8.95") }
end
end

0 comments on commit e4f3e5e

Please sign in to comment.