efo_nelfo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +8 -0
- data/efo_nelfo.gemspec +27 -0
- data/lib/efo_nelfo/array.rb +10 -0
- data/lib/efo_nelfo/attribute_assignment.rb +13 -0
- data/lib/efo_nelfo/errors.rb +4 -0
- data/lib/efo_nelfo/foo.rb +26 -0
- data/lib/efo_nelfo/post_type.rb +51 -0
- data/lib/efo_nelfo/property.rb +132 -0
- data/lib/efo_nelfo/reader/csv.rb +67 -0
- data/lib/efo_nelfo/v40/order/line.rb +38 -0
- data/lib/efo_nelfo/v40/order/order.rb +102 -0
- data/lib/efo_nelfo/v40/order/text.rb +22 -0
- data/lib/efo_nelfo/version.rb +3 -0
- data/lib/efo_nelfo.rb +35 -0
- data/spec/csv_writer_spec.rb +51 -0
- data/spec/efo_nelfo_spec.rb +114 -0
- data/spec/property_spec.rb +125 -0
- data/spec/samples/B028579.594.csv +2 -0
- data/spec/samples/B028579.595.csv +4 -0
- data/spec/samples/B028579.596.csv +9 -0
- data/spec/samples/B028579.597.csv +17 -0
- data/spec/samples/B123.V3.csv +2 -0
- data/spec/samples/B650517.030.csv +4 -0
- data/spec/samples/B650517.031.csv +2 -0
- data/spec/samples/B650517.032.csv +3 -0
- data/spec/samples/V4_varefil.csv +3139 -0
- data/spec/spec_helper.rb +6 -0
- metadata +173 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe EfoNelfo::V40::Order do
|
5
|
+
let(:order) { EfoNelfo::V40::Order.new buyer_id: '123', customer_id: '456' }
|
6
|
+
let(:csv) { order.to_csv }
|
7
|
+
|
8
|
+
describe "to_a" do
|
9
|
+
|
10
|
+
it "returns an array" do
|
11
|
+
order.to_a.size.must_equal 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it "includes the lines" do
|
15
|
+
order.add EfoNelfo::V40::Order::Line.new
|
16
|
+
order.add EfoNelfo::V40::Order::Line.new
|
17
|
+
order.to_a.size.must_equal 3
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "to_csv" do
|
23
|
+
before do
|
24
|
+
order.add EfoNelfo::V40::Order::Line.new(order_number: 'foo', item_name: 'Ware')
|
25
|
+
order.add EfoNelfo::V40::Order::Text.new text: 'haha'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "includes standard fields" do
|
29
|
+
csv.must_match /;EFONELFO;/
|
30
|
+
csv.must_match /;4.0;/
|
31
|
+
csv.must_match /;123;/
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can be parsed" do
|
35
|
+
o = EfoNelfo.parse(csv)
|
36
|
+
o.must_be_instance_of EfoNelfo::V40::Order
|
37
|
+
o.lines.first.text.must_be_instance_of EfoNelfo::V40::Order::Text
|
38
|
+
end
|
39
|
+
|
40
|
+
it "adds order lines" do
|
41
|
+
order.add EfoNelfo::V40::Order::Line.new(order_number: 'foo', item_name: 'Ware')
|
42
|
+
csv.must_match /Ware/
|
43
|
+
end
|
44
|
+
|
45
|
+
it "adds text to order line" do
|
46
|
+
csv.must_match /haha/
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
# helper method that returns full path to csv files
|
5
|
+
def csv(filename)
|
6
|
+
File.expand_path("../samples/#{filename}", __FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe EfoNelfo do
|
10
|
+
|
11
|
+
describe "properties" do
|
12
|
+
it "is accessible as alias" do
|
13
|
+
order = EfoNelfo::V40::Order.new
|
14
|
+
order.buyer_id = "123"
|
15
|
+
order.KjøpersId.must_equal "123"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can update the variable using the alias" do
|
19
|
+
order = EfoNelfo::V40::Order.new
|
20
|
+
order.KjøpersId = "foo"
|
21
|
+
order.buyer_id.must_equal "foo"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has custom setters" do
|
25
|
+
EfoNelfo::V40::Order.new(delivery_date: "20110402").delivery_date.must_be_kind_of Date
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".parse" do
|
31
|
+
|
32
|
+
it "parses CSV and does the same as .load" do
|
33
|
+
filename = csv('B650517.032.csv')
|
34
|
+
parsed = EfoNelfo.parse File.read(filename)
|
35
|
+
loaded = EfoNelfo.load filename
|
36
|
+
parsed.source.must_equal loaded.source
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".load" do
|
42
|
+
|
43
|
+
describe "when passing in invalid file" do
|
44
|
+
it "raises an exception" do
|
45
|
+
lambda { EfoNelfo.load 'foo' }.must_raise Errno::ENOENT
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "passing a Order file" do
|
50
|
+
|
51
|
+
it "uses the correct version" do
|
52
|
+
lambda { EfoNelfo.load(csv('B123.v3.csv')) }.must_raise EfoNelfo::UnsupportedPostType
|
53
|
+
end
|
54
|
+
|
55
|
+
it "parses the file and returns an Order" do
|
56
|
+
EfoNelfo.load(csv('B650517.032.csv')).must_be_instance_of EfoNelfo::V40::Order
|
57
|
+
end
|
58
|
+
|
59
|
+
it "the order contains order information" do
|
60
|
+
order = EfoNelfo.load(csv('B650517.032.csv'))
|
61
|
+
order.post_type.must_equal 'BH'
|
62
|
+
order.post_type_human.must_equal 'Bestilling Hodepost'
|
63
|
+
order.format.must_equal 'EFONELFO'
|
64
|
+
order.version.must_equal '4.0'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "the order contains orderlines" do
|
68
|
+
order = EfoNelfo.load(csv('B650517.032.csv'))
|
69
|
+
|
70
|
+
line = order.lines.first
|
71
|
+
line.must_be_instance_of EfoNelfo::V40::Order::Line
|
72
|
+
|
73
|
+
line.post_type.must_equal 'BL'
|
74
|
+
line.post_type_human.must_equal 'Bestilling vareLinjepost'
|
75
|
+
|
76
|
+
line.index.must_equal 1
|
77
|
+
line.order_number.must_equal '1465'
|
78
|
+
line.item_count.must_equal 200
|
79
|
+
line.price_unit.must_equal "EA"
|
80
|
+
line.buyer_item_number.must_be_nil
|
81
|
+
line.delivery_date.must_equal Date.new(2010, 6, 1)
|
82
|
+
line.buyer_ref.must_be_nil
|
83
|
+
line.splitable.must_equal true
|
84
|
+
line.replacable.must_equal true
|
85
|
+
|
86
|
+
line.item_type.must_equal 1
|
87
|
+
line.item_number.must_equal '8000502'
|
88
|
+
line.item_name.must_equal '200L OSO STD BEREDER SUPER S'
|
89
|
+
line.item_description.must_be_nil
|
90
|
+
end
|
91
|
+
|
92
|
+
it "adds text to orderline" do
|
93
|
+
order = EfoNelfo.load(csv('B650517.032.csv'))
|
94
|
+
line = order.lines.first
|
95
|
+
line.text.to_s.must_equal "Her er litt fritekst"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "stores the contents file in the Order object" do
|
99
|
+
filename = csv('B650517.032.csv')
|
100
|
+
order = EfoNelfo.load(filename)
|
101
|
+
order.source.must_equal File.read(filename)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Loads all files in the samples directory
|
106
|
+
%w(B028579.594.csv B028579.596.csv B650517.031.csv B028579.595.csv B028579.597.csv B650517.030.csv B650517.032.csv).each do |file|
|
107
|
+
it "can load #{file}" do
|
108
|
+
EfoNelfo.load(csv(file)).must_be_instance_of EfoNelfo::V40::Order
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe EfoNelfo::Property do
|
5
|
+
|
6
|
+
class Foo
|
7
|
+
include EfoNelfo::Property
|
8
|
+
property :foo, alias: "Føbar", limit: 3, default: 'I am foo'
|
9
|
+
property :bar
|
10
|
+
property :date, type: :date
|
11
|
+
property :number, type: :integer
|
12
|
+
property :doable, type: :boolean, default: false
|
13
|
+
property :immutable, read_only: true, default: 'NO'
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:obj) { Foo.new }
|
17
|
+
|
18
|
+
it "raises an error if trying to add duplicate property" do
|
19
|
+
lambda {
|
20
|
+
class Bar
|
21
|
+
include EfoNelfo::Property
|
22
|
+
property :foo
|
23
|
+
property :foo
|
24
|
+
end
|
25
|
+
}.must_raise EfoNelfo::DuplicateProperty
|
26
|
+
end
|
27
|
+
|
28
|
+
it "adds a getter and setter for foo" do
|
29
|
+
obj.foo = 'Test'
|
30
|
+
obj.foo.must_equal 'Test'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "adds an alias getter and setter for foo" do
|
34
|
+
obj.foo = 'Test'
|
35
|
+
obj.Føbar.must_equal 'Test'
|
36
|
+
obj.Føbar = 'Hacked'
|
37
|
+
obj.Føbar.must_equal 'Hacked'
|
38
|
+
obj.foo.must_equal 'Hacked'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "assigns default values" do
|
42
|
+
obj.bar.must_be_nil
|
43
|
+
obj.foo.must_equal 'I am foo'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "can be assigned nil values" do
|
47
|
+
obj.number = nil
|
48
|
+
obj.number.must_be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "readonly attributes cannot be changed" do
|
52
|
+
lambda { obj.immutable = 'test' }.must_raise NoMethodError
|
53
|
+
obj.immutable.must_equal 'NO'
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "property types" do
|
57
|
+
describe ":date" do
|
58
|
+
it "converts strings to dates" do
|
59
|
+
obj.date = "20100504"
|
60
|
+
obj.date.must_be_kind_of Date
|
61
|
+
end
|
62
|
+
|
63
|
+
it "accepts a Date" do
|
64
|
+
obj.date = Date.new 2010, 5, 4
|
65
|
+
obj.date.must_be_kind_of Date
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
it "handles :integer" do
|
71
|
+
obj.number = "2"
|
72
|
+
obj.number.must_equal 2
|
73
|
+
end
|
74
|
+
|
75
|
+
describe ":boolean" do
|
76
|
+
it "returns true when assigning blank string" do
|
77
|
+
obj.doable = ''
|
78
|
+
obj.doable?.must_equal true
|
79
|
+
end
|
80
|
+
|
81
|
+
it "returns true when assigning nil" do
|
82
|
+
obj.doable = nil
|
83
|
+
obj.doable?.must_equal true
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns true when assigning 'J'" do
|
87
|
+
obj.doable = 'J'
|
88
|
+
obj.doable?.must_equal true
|
89
|
+
end
|
90
|
+
|
91
|
+
it "returns false" do
|
92
|
+
obj.doable = false
|
93
|
+
obj.doable?.must_equal false
|
94
|
+
|
95
|
+
obj.doable = 'N'
|
96
|
+
obj.doable?.must_equal false
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe ".properties" do
|
105
|
+
let(:props) { Foo.properties }
|
106
|
+
|
107
|
+
it "includes the properties" do
|
108
|
+
props[:foo].must_be_kind_of Hash
|
109
|
+
end
|
110
|
+
|
111
|
+
it "includes the property options" do
|
112
|
+
props[:foo][:limit].must_equal 3
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#to_a" do
|
117
|
+
it "returns array of all attributes in correct order" do
|
118
|
+
obj.date = Date.new 2012, 5, 30
|
119
|
+
obj.number = 3
|
120
|
+
obj.doable = true
|
121
|
+
obj.to_a.must_equal ["I am foo", nil, "20120530", 3, "J", "NO"]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
@@ -0,0 +1,4 @@
|
|
1
|
+
BH;EFONELFO;4.0;;NO950349875MVA;2113;28579;;;;;;;;;;;;2113;;;;20100615;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2
|
+
BL;1;2113;1;2215316;75 x 2,6 x 3000mm sort PP r�r;;3000;MTR;;20100615;;;
|
3
|
+
BL;2;2113;1;5002202;12 x 1.0mm kobberr�r f/kap.lod;;3000;MTR;;20100615;;;
|
4
|
+
BL;3;2113;1;5002203;15 x 1.0mm kobberr�r f/kap.lod;;3000;MTR;;20100615;;;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
BH;EFONELFO;4.0;;NO950349875MVA;2116;28579;;;;;;;;;;LAGER;;2116/LAGER;;;;20100617;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2
|
+
BL;1;2116;1;5030026;15 mm 1/1 bend m/1 muffe 5001A;;5000;EA;;20100617;;;
|
3
|
+
BL;2;2116;1;5030213;12 mm 1/1 bend m/2 muffer;;5000;EA;;20100617;;;
|
4
|
+
BL;3;2116;1;5030216;15 mm 1/1 bend m/2 muffer;;5000;EA;;20100617;;;
|
5
|
+
BL;4;2116;1;5030219;18 mm 1/1 bend m/2 muffer;;2000;EA;;20100617;;;
|
6
|
+
BL;5;2116;1;5034253;22 x 18 mm overg.nipl. 5243;;1000;EA;;20100617;;;
|
7
|
+
BL;6;2116;1;4516183;FALU SNAP ENK 10-16 MM HVIT;;5000;EA;;20100617;;;
|
8
|
+
BL;7;2116;1;4516273;FALU SNAP ENK 18-22 MM HVIT;;1000;EA;;20100617;;;
|
9
|
+
BL;8;2116;1;4516271;FALU SNAP DOB 18-22 MM 40 CC;;1000;EA;;20100617;;;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
BH;EFONELFO;4.0;;NO950349875MVA;2124;28579;;;;;;;;;;;;2124;;;;20100621;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2
|
+
BL;1;2124;1;2215334;110 mm x 45� sort PP bend;;3000;EA;;20100621;;;
|
3
|
+
BL;2;2124;1;2215338;110 mm x 88� sort PP bend;;3000;EA;;20100621;;;
|
4
|
+
BL;3;2124;1;2215337;75 mm x 88� sort PP bend;;3000;EA;;20100621;;;
|
5
|
+
BL;4;2124;1;2215328;75 mm x 15� sort PP bend;;3000;EA;;20100621;;;
|
6
|
+
BL;5;2124;1;2215331;75 mm x 30� sort PP bend;;3000;EA;;20100621;;;
|
7
|
+
BL;6;2124;1;2215333;75 mm x 45� sort PP bend;;3000;EA;;20100621;;;
|
8
|
+
BL;7;2124;1;2215324;75 mm sort PP dobbeltmuffe;;3000;EA;;20100621;;;
|
9
|
+
BL;8;2124;1;2215325;110 mm sort PP dobbeltmuffe;;3000;EA;;20100621;;;
|
10
|
+
BL;9;2124;1;2215326;75 mm sort PP l�pemuffe Wafix;;3000;EA;;20100621;;;
|
11
|
+
BL;10;2124;1;2214523;32 mm x 15' PP-HT bend hvit;;3000;EA;;20100621;;;
|
12
|
+
BL;11;2124;1;2214527;32 mm x 30' PP-HT bend hvit;;3000;EA;;20100621;;;
|
13
|
+
BL;12;2124;1;2214534;32 mm x 45' PP-HT bend hvit;;3000;EA;;20100621;;;
|
14
|
+
BL;13;2124;1;2214512;32 mm PP-HT l�pemuffe hvit;;3000;EA;;20100621;;;
|
15
|
+
BL;14;2124;1;2214502;32 mm PP-HT dobbelmuffe hvit;;3000;EA;;20100621;;;
|
16
|
+
BL;15;2124;1;2214553;32 x 32 mm x 45' PP-HT gren;;1000;EA;;20100621;;;
|
17
|
+
BL;16;2124;1;5110093;15x1/2" Q&E veggboks M6 enkel;;3000;EA;;20100621;;;
|
@@ -0,0 +1,4 @@
|
|
1
|
+
BH;EFONELFO;4.0;;NO986692002MVA;1464;650517;;;5000;;5000;;;;;lager;;1464/5000/lager;;;;20100601;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2
|
+
BL;1;1464;1;5118157;25 MM ROTH SKAPGJENNOMF�RING;;2000;EA;;20100601;;;
|
3
|
+
BL;2;1464;1;5118207;ROTH ENKEL KLAMMER 25MM;;5000;EA;;20100601;;;
|
4
|
+
BL;3;1464;1;5118214;ROTH KLAMMER DOBBEL 25 MM;;5000;EA;;20100601;;;
|