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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 987087ce328532ef45bd6b3cb8f037b654b5d54a
4
- data.tar.gz: 68e4084d01fcbc30ec678b812a7b1d372d333bd6
3
+ metadata.gz: fd81f9243df3f59ad32b14865d2da1e63c37d0e4
4
+ data.tar.gz: dd5f165f594e2dfcdbaef5fb7b458be314e11972
5
5
  SHA512:
6
- metadata.gz: ce3f9f28374eb3c9f45efa5323e8380442c1eee93bd8480d06a5b9d207a30545cc048d0db26b56853bc374b408867c0e9ca31086519a699ef03092631d57ef53
7
- data.tar.gz: a61783e854102ca0ac932ea442fe964a75f1373893a38a1e75399c98c9b770783d5155e2e172597334385ff020a45c8aa5e9d27b462206232fc51f5847f5319b
6
+ metadata.gz: 288548f3e56f2726b62e50f5a285831f486c90f778605f237b4ad17b2904169d00163c488d202db5ddca3caceb63a8cf971a9b4d90afc72df30f3482cb588a62
7
+ data.tar.gz: 51d44365d5bcbadf58235ba70e3b8614ea518d6d650c8cdfb672b9e7145eb4d1dbad3cc90cc06c6006b6362cb1587e1daab36addab0957537e71f5f3e6a69c77
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # EfoNelfo
2
2
 
3
+ [![Codeship Status for rorkjop/efonelfo](https://codeship.com/projects/2f24e110-26db-0133-3264-3e76e843c90e/status?branch=master)](https://codeship.com/projects/97199)
4
+ [![Code Climate](https://codeclimate.com/github/rorkjop/efonelfo/badges/gpa.svg)](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 item_number: '442', order_number: 'abc'
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 "turn"
31
+ spec.add_development_dependency "codeclimate-test-reporter"
31
32
  end
data/lib/efo_nelfo.rb CHANGED
@@ -23,6 +23,14 @@ module EfoNelfo
23
23
 
24
24
  class << self
25
25
 
26
+ def strict_mode?
27
+ @strict_mode || false
28
+ end
29
+
30
+ def strict_mode=(mode)
31
+ @strict_mode = mode
32
+ end
33
+
26
34
  def load(filename)
27
35
  Reader::CSV.new(filename: filename).parse
28
36
  end
@@ -27,7 +27,7 @@ module EfoNelfo
27
27
 
28
28
  # Returns all property values as array formatted for csv
29
29
  def to_a
30
- properties.values.map &:to_csv
30
+ properties.values.map(&:to_csv)
31
31
  end
32
32
 
33
33
  private
@@ -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
@@ -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
@@ -20,10 +20,6 @@ module EfoNelfo
20
20
 
21
21
  has_many :text, post_type: "BT"
22
22
 
23
- def format_item_count
24
- item_count ? item_count * 100 : nil
25
- end
26
-
27
23
  end
28
24
 
29
25
  end
@@ -1,3 +1,3 @@
1
1
  module EfoNelfo
2
- VERSION = "1.5.3"
2
+ VERSION = "1.5.4"
3
3
  end
@@ -39,17 +39,17 @@ describe EfoNelfo::Collection do
39
39
  describe "<<" do
40
40
 
41
41
  describe "passing a hash" do
42
- let(:hash) {
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 << hash
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 << hash
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
@@ -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 /;EFONELFO;/
30
- csv.must_match /;4.0;/
31
- csv.must_match /;123;/
32
- csv.must_match /;456;/
33
- csv.must_match /;J;/ # for fixing sublime syntax highlighting: /
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 /Ware/
44
+ csv.must_match(/Ware/)
45
45
  end
46
46
 
47
47
  it "adds text to order line" do
48
- csv.must_match /BT;haha/
48
+ csv.must_match(/BT;haha/)
49
49
  end
50
50
 
51
51
  end
@@ -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-efg",
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-efg"
46
+ order.order_number.must_equal "abc-123-ef"
47
47
  order.seller_warehouse.must_equal "Somewhere"
48
48
  end
49
49
 
@@ -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.v3.csv')) }.must_raise EfoNelfo::UnsupportedPostType
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
@@ -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 "NO1234567879MVA"
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)
@@ -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 /AB;21;123.+XY;41/m
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(:hash) {
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 hash }
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
@@ -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 = 'Test'
43
- obj.foo.must_equal 'Test'
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 = 'Test'
59
- obj.Føbar.must_equal 'Test'
60
- obj.Føbar = 'Hacked'
61
- obj.Føbar.must_equal 'Hacked'
62
- obj.foo.must_equal 'Hacked'
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;NO1234567879MVA;;;20040122;;NOK;;ONNINEN A/S;P.B. 70;;1483;SKYTTA;NO;;
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 'efo_nelfo'
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
2
3
 
3
- require 'turn/autorun'
4
+ require 'efo_nelfo'
5
+ require 'minitest/autorun'
4
6
  require 'minitest/spec'
5
- require 'minitest/pride'
7
+ require 'minitest/reporters'
6
8
  require 'awesome_print'
7
9
 
8
- Turn.config do |c|
9
- c.format = :progress
10
- c.natural = true
11
- c.loadpath = %w(lib spec)
12
- end
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 &block
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.3
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-16 00:00:00.000000000 Z
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: turn
154
+ name: codeclimate-test-reporter
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
157
  - - ">="