efo_nelfo 1.5.3 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/efo_nelfo.gemspec +2 -1
- data/lib/efo_nelfo.rb +8 -0
- data/lib/efo_nelfo/properties.rb +1 -1
- data/lib/efo_nelfo/property.rb +29 -11
- data/lib/efo_nelfo/v40/bh.rb +0 -11
- data/lib/efo_nelfo/v40/bl.rb +0 -4
- data/lib/efo_nelfo/version.rb +1 -1
- data/spec/collection_spec.rb +3 -3
- data/spec/csv_writer_spec.rb +7 -7
- data/spec/efo_nelfo_spec.rb +2 -2
- data/spec/parsing/bh_spec.rb +1 -1
- data/spec/parsing/vh_spec.rb +1 -1
- data/spec/post_type_spec.rb +3 -3
- data/spec/properties_spec.rb +36 -7
- data/spec/samples/varefil_eksempel.csv +1 -1
- data/spec/spec_helper.rb +11 -9
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd81f9243df3f59ad32b14865d2da1e63c37d0e4
|
4
|
+
data.tar.gz: dd5f165f594e2dfcdbaef5fb7b458be314e11972
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 288548f3e56f2726b62e50f5a285831f486c90f778605f237b4ad17b2904169d00163c488d202db5ddca3caceb63a8cf971a9b4d90afc72df30f3482cb588a62
|
7
|
+
data.tar.gz: 51d44365d5bcbadf58235ba70e3b8614ea518d6d650c8cdfb672b9e7145eb4d1dbad3cc90cc06c6006b6362cb1587e1daab36addab0957537e71f5f3e6a69c77
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# EfoNelfo
|
2
2
|
|
3
|
+
[](https://codeship.com/projects/97199)
|
4
|
+
[](https://codeclimate.com/github/rorkjop/efonelfo)
|
5
|
+
|
3
6
|
Gem for parsing and writing EfoNelfo documents.
|
4
7
|
|
5
8
|
Supported EfoNelfo versions:
|
@@ -17,7 +20,7 @@ Supported formats:
|
|
17
20
|
Importing a CSV file:
|
18
21
|
|
19
22
|
# EfoNelfo.load "B12345678.332.csv" # => EfoNelfo::V40::VH
|
20
|
-
|
23
|
+
|
21
24
|
Parsing CSV:
|
22
25
|
|
23
26
|
# EfoNelfo.parse "VH;EFONELFO;4.0;foo;bar" # => EfoNelfo::V40::VH
|
@@ -25,8 +28,9 @@ Parsing CSV:
|
|
25
28
|
Exporting CSV:
|
26
29
|
|
27
30
|
# order = EfoNelfo::V40::VH.new
|
28
|
-
# order.add EfoNelfo::V40::VL.new
|
31
|
+
# order.add EfoNelfo::V40::VL.new name: 'Something', price: 10
|
29
32
|
# order.to_csv
|
33
|
+
# => "VH;EFONELFO;4.0;;;;;;;;;;;;;;\r\nVL;;;Something;;;;;10;;;;;;;;;;;\r\n"
|
30
34
|
|
31
35
|
|
32
36
|
## TODO
|
data/efo_nelfo.gemspec
CHANGED
@@ -24,8 +24,9 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "guard"
|
25
25
|
spec.add_development_dependency "guard-minitest"
|
26
26
|
spec.add_development_dependency "minitest"
|
27
|
+
spec.add_development_dependency "minitest-reporters"
|
27
28
|
spec.add_development_dependency "rb-fsevent"
|
28
29
|
spec.add_development_dependency "terminal-notifier"
|
29
30
|
spec.add_development_dependency "terminal-notifier-guard"
|
30
|
-
spec.add_development_dependency "
|
31
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
31
32
|
end
|
data/lib/efo_nelfo.rb
CHANGED
data/lib/efo_nelfo/properties.rb
CHANGED
data/lib/efo_nelfo/property.rb
CHANGED
@@ -43,17 +43,7 @@ module EfoNelfo
|
|
43
43
|
# (string) value = 'foo' # => 'foo'
|
44
44
|
def value=(new_value)
|
45
45
|
return nil if readonly?
|
46
|
-
|
47
|
-
@value = case
|
48
|
-
when boolean?
|
49
|
-
new_value.nil? || new_value == true || new_value == 'J' || new_value == 'j' || new_value == '' ? true : false
|
50
|
-
when date?
|
51
|
-
new_value.is_a?(Date) ? new_value : Date.parse(new_value) rescue nil
|
52
|
-
when integer?
|
53
|
-
new_value.nil? && !required? ? nil : new_value.to_i
|
54
|
-
else
|
55
|
-
new_value
|
56
|
-
end
|
46
|
+
@value = send("sanitize_#{options[:type]}", new_value)
|
57
47
|
end
|
58
48
|
|
59
49
|
# returns formatted value suitable for csv output
|
@@ -91,6 +81,34 @@ module EfoNelfo
|
|
91
81
|
options.has_key?(args.first) ? options[args.first] : super
|
92
82
|
end
|
93
83
|
|
84
|
+
private
|
85
|
+
|
86
|
+
def sanitize_integer(value)
|
87
|
+
value.nil? && !required? ? nil : value.to_i
|
88
|
+
end
|
89
|
+
|
90
|
+
def sanitize_boolean(value)
|
91
|
+
value.nil? || value == true || value == 'J' || value == 'j' || value == '' ? true : false
|
92
|
+
end
|
93
|
+
|
94
|
+
def sanitize_date(value)
|
95
|
+
value.is_a?(Date) ? value : Date.parse(value) rescue nil
|
96
|
+
end
|
97
|
+
|
98
|
+
def sanitize_string(value)
|
99
|
+
return nil if value.nil?
|
100
|
+
return value unless value.is_a?(String)
|
101
|
+
|
102
|
+
string = value.to_s
|
103
|
+
|
104
|
+
if EfoNelfo.strict_mode? && (options[:limit] && string.length > options[:limit])
|
105
|
+
raise ArgumentError.new("Value exceeds limit")
|
106
|
+
else
|
107
|
+
string.slice(0, options[:limit])
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
94
112
|
end
|
95
113
|
|
96
114
|
end
|
data/lib/efo_nelfo/v40/bh.rb
CHANGED
@@ -56,17 +56,6 @@ module EfoNelfo
|
|
56
56
|
|
57
57
|
has_many :lines, post_type: "BL"
|
58
58
|
|
59
|
-
# def add(post_type)
|
60
|
-
# case
|
61
|
-
# when post_type.is_a?(BL)
|
62
|
-
# add_order_line(post_type)
|
63
|
-
# when post_type.is_a?(BT)
|
64
|
-
# add_text_to_order_line(post_type)
|
65
|
-
# when post_type.is_a?(Hash)
|
66
|
-
# add_order_line(EfoNelfo::V40::BL.new(post_type))
|
67
|
-
# end
|
68
|
-
# end
|
69
|
-
|
70
59
|
private
|
71
60
|
|
72
61
|
# Appends a order line to the order
|
data/lib/efo_nelfo/v40/bl.rb
CHANGED
data/lib/efo_nelfo/version.rb
CHANGED
data/spec/collection_spec.rb
CHANGED
@@ -39,17 +39,17 @@ describe EfoNelfo::Collection do
|
|
39
39
|
describe "<<" do
|
40
40
|
|
41
41
|
describe "passing a hash" do
|
42
|
-
let(:
|
42
|
+
let(:a_hash) {
|
43
43
|
{ post_type: "BT", version: "2.1", whatever: 'blah' }
|
44
44
|
}
|
45
45
|
|
46
46
|
it "accepts a valid hash" do
|
47
|
-
array <<
|
47
|
+
array << a_hash
|
48
48
|
array.size.must_equal 1
|
49
49
|
end
|
50
50
|
|
51
51
|
it "converts the hash into a post type" do
|
52
|
-
array <<
|
52
|
+
array << a_hash
|
53
53
|
array[0].must_be_instance_of EfoNelfo::V21::BT
|
54
54
|
array[0].whatever.must_equal 'blah'
|
55
55
|
end
|
data/spec/csv_writer_spec.rb
CHANGED
@@ -26,11 +26,11 @@ describe EfoNelfo::V40::BH do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "includes standard fields" do
|
29
|
-
csv.must_match
|
30
|
-
csv.must_match
|
31
|
-
csv.must_match
|
32
|
-
csv.must_match
|
33
|
-
csv.must_match
|
29
|
+
csv.must_match(/;EFONELFO;/)
|
30
|
+
csv.must_match(/;4.0;/)
|
31
|
+
csv.must_match(/;123;/)
|
32
|
+
csv.must_match(/;456;/)
|
33
|
+
csv.must_match(/;J;/)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "can be parsed" do
|
@@ -41,11 +41,11 @@ describe EfoNelfo::V40::BH do
|
|
41
41
|
|
42
42
|
it "adds order lines" do
|
43
43
|
order.add EfoNelfo::V40::BL.new(order_number: 'foo', item_name: 'Ware')
|
44
|
-
csv.must_match
|
44
|
+
csv.must_match(/Ware/)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "adds text to order line" do
|
48
|
-
csv.must_match
|
48
|
+
csv.must_match(/BT;haha/)
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
data/spec/efo_nelfo_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe EfoNelfo do
|
|
25
25
|
describe "assign via hash" do
|
26
26
|
let(:json) {
|
27
27
|
{ customer_id: "123",
|
28
|
-
order_number: "abc-123-
|
28
|
+
order_number: "abc-123-ef",
|
29
29
|
seller_warehouse: "Somewhere",
|
30
30
|
label: "Some label",
|
31
31
|
lines: [
|
@@ -43,7 +43,7 @@ describe EfoNelfo do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "assigns attributes" do
|
46
|
-
order.order_number.must_equal "abc-123-
|
46
|
+
order.order_number.must_equal "abc-123-ef"
|
47
47
|
order.seller_warehouse.must_equal "Somewhere"
|
48
48
|
end
|
49
49
|
|
data/spec/parsing/bh_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe "parsing a BH.csv file" do
|
4
4
|
|
5
5
|
it "uses the correct version" do
|
6
|
-
lambda { EfoNelfo.load(csv('B123.
|
6
|
+
lambda { EfoNelfo.load(csv('B123.V3.csv')) }.must_raise EfoNelfo::UnsupportedPostType
|
7
7
|
end
|
8
8
|
|
9
9
|
it "parses the file and returns an Order" do
|
data/spec/parsing/vh_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe "parsing a VH.csv file" do
|
|
10
10
|
nelfo.format.must_equal "EFONELFO"
|
11
11
|
nelfo.version.must_equal "4.0"
|
12
12
|
nelfo.post_type.must_equal "VH"
|
13
|
-
nelfo.SelgersId.must_equal "
|
13
|
+
nelfo.SelgersId.must_equal "NO123456787MVA"
|
14
14
|
nelfo.KjøpersId.must_be_nil
|
15
15
|
nelfo.KundeNr.must_be_nil
|
16
16
|
nelfo.from_date.must_equal Date.new(2004, 1, 22)
|
data/spec/post_type_spec.rb
CHANGED
@@ -38,12 +38,12 @@ describe EfoNelfo::PostType do
|
|
38
38
|
it "converts the posttype to csv" do
|
39
39
|
pt = EfoNelfo::V21::AB.new seller_id: '123'
|
40
40
|
pt.lines << EfoNelfo::V21::XY.new(order_number: '41')
|
41
|
-
pt.to_csv.must_match
|
41
|
+
pt.to_csv.must_match(/AB;21;123.+XY;41/m)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe ".from" do
|
46
|
-
let(:
|
46
|
+
let(:a_hash) {
|
47
47
|
{
|
48
48
|
post_type: "AB",
|
49
49
|
version: "2.1",
|
@@ -54,7 +54,7 @@ describe EfoNelfo::PostType do
|
|
54
54
|
}
|
55
55
|
}
|
56
56
|
|
57
|
-
let(:pt) { EfoNelfo::PostType.from
|
57
|
+
let(:pt) { EfoNelfo::PostType.from a_hash }
|
58
58
|
|
59
59
|
it "converts the hash into a valid posttype" do
|
60
60
|
pt.must_be_instance_of EfoNelfo::V21::AB
|
data/spec/properties_spec.rb
CHANGED
@@ -39,8 +39,37 @@ describe EfoNelfo::Properties do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "adds a setter method for :foo" do
|
42
|
-
obj.foo = '
|
43
|
-
obj.foo.must_equal '
|
42
|
+
obj.foo = 'abc'
|
43
|
+
obj.foo.must_equal 'abc'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "cuts off strings longer than the limit" do
|
47
|
+
obj.foo = "Long string"
|
48
|
+
obj.foo.must_equal "Lon"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "won't cut off strings" do
|
52
|
+
# bar has no limit specified, uses defaults
|
53
|
+
obj.bar = "hahaha"
|
54
|
+
obj.bar.must_equal "hahaha"
|
55
|
+
|
56
|
+
# numbers are ignored, even if specified type is string
|
57
|
+
obj.bar = 123
|
58
|
+
obj.bar.must_equal 123
|
59
|
+
|
60
|
+
obj.foo = 123456
|
61
|
+
obj.foo.must_equal 123456
|
62
|
+
|
63
|
+
obj.foo = "123456"
|
64
|
+
obj.foo.must_equal "123"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "raises exception if string is longer than limit and strict_mode is enabled" do
|
68
|
+
EfoNelfo.strict_mode = true
|
69
|
+
lambda {
|
70
|
+
obj.foo = "Long"
|
71
|
+
}.must_raise ArgumentError
|
72
|
+
EfoNelfo.strict_mode = false
|
44
73
|
end
|
45
74
|
|
46
75
|
it "adds a question method for boolean types" do
|
@@ -55,11 +84,11 @@ describe EfoNelfo::Properties do
|
|
55
84
|
end
|
56
85
|
|
57
86
|
it "adds an alias getter and setter for foo" do
|
58
|
-
obj.foo = '
|
59
|
-
obj.Føbar.must_equal '
|
60
|
-
obj.Føbar = '
|
61
|
-
obj.Føbar.must_equal '
|
62
|
-
obj.foo.must_equal '
|
87
|
+
obj.foo = 'ABC'
|
88
|
+
obj.Føbar.must_equal 'ABC'
|
89
|
+
obj.Føbar = 'CDE'
|
90
|
+
obj.Føbar.must_equal 'CDE'
|
91
|
+
obj.foo.must_equal 'CDE'
|
63
92
|
end
|
64
93
|
|
65
94
|
it "assigns default values" do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
VH;EFONELFO;4.0;
|
1
|
+
VH;EFONELFO;4.0;NO123456787MVA;;;20040122;;NOK;;ONNINEN A/S;P.B. 70;;1483;SKYTTA;NO;;
|
2
2
|
VL;1;1006100;MATTE 3MM 100W/M2 100W;1,0 m2 0,5 x 2,0 m;1;EA;STYKK;55300;10000;20110901;1;;1004;;;J;10000;0;
|
3
3
|
VA;1;;P;5000000;;;;;;;;;;;;;
|
4
4
|
VA;1;1016099;A;;;;;;;;;;;;;;
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
require '
|
1
|
+
require 'codeclimate-test-reporter'
|
2
|
+
CodeClimate::TestReporter.start
|
2
3
|
|
3
|
-
require '
|
4
|
+
require 'efo_nelfo'
|
5
|
+
require 'minitest/autorun'
|
4
6
|
require 'minitest/spec'
|
5
|
-
require 'minitest/
|
7
|
+
require 'minitest/reporters'
|
6
8
|
require 'awesome_print'
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
Minitest::Reporters.use!(
|
11
|
+
Minitest::Reporters::SpecReporter.new,
|
12
|
+
ENV,
|
13
|
+
Minitest.backtrace_filter
|
14
|
+
)
|
13
15
|
|
14
16
|
# helper method that returns full path to csv files
|
15
17
|
def csv(filename)
|
@@ -23,7 +25,7 @@ class MiniTest::Spec
|
|
23
25
|
let(:inner_subject) { subject.send(attribute) }
|
24
26
|
|
25
27
|
it "verify subject.#{attribute} for" do
|
26
|
-
inner_subject.instance_eval
|
28
|
+
inner_subject.instance_eval(&block)
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: efo_nelfo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gudleik Rasch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-reporters
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rb-fsevent
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,7 +151,7 @@ dependencies:
|
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
154
|
+
name: codeclimate-test-reporter
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
157
|
- - ">="
|