efo_nelfo 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2be2ec103dd949a5ec7dc352e3fd75b14037759f
4
- data.tar.gz: 81fc193b3094f419feebd8c70d31164ca9b837a1
3
+ metadata.gz: 6b620fd9d75306ced61c3f6148388f8374b72571
4
+ data.tar.gz: 71f2bc405a4d973c56fe69c802e18863889ec9e0
5
5
  SHA512:
6
- metadata.gz: b2464557f24b9cbef36ec4019f3816b0873b7f9f40c140365f2d37465b97e1947274ab1acaff3b5bc63ef34941fbfd30a38b0cc6fb00decc8880e305c48aa88b
7
- data.tar.gz: d65c80d75dec5d230ea5e12fc6659ed354ce077edaaef655f2e50ee4bbfb0b4a8a75893624b468ea45c7131288b974a1061a1cfaaa397b32019c9589ae7fc5a7
6
+ metadata.gz: df7f92694016d934b40b32ba5ae9789b14a403026f4a9fa0ea100c873ea6eedf5bbed937901fd5417cbb2362e9a8afa000aa83cee78651b79a5a68f2d8f32ee9
7
+ data.tar.gz: ce15e9bd79b5ef9de7165241eec3ab69e23da57241f74f077ae05bd40fd29515925755a7b6a0f465082b9cfb3b2cdb33e34724ac88c49f97ab8da4dda6e0cf03
@@ -6,7 +6,7 @@ module EfoNelfo
6
6
  include Enumerable
7
7
  extend Forwardable
8
8
 
9
- def_delegators :@list, :each, :<<, :last
9
+ def_delegators :@list, :[], :each, :<<, :last, :size, :empty?
10
10
 
11
11
  def initialize(*args)
12
12
  @list = []
@@ -24,13 +24,21 @@ module EfoNelfo
24
24
  property :splitable, alias: :DelLev, type: :boolean, default: true
25
25
  property :replacable, alias: :AltKode, type: :boolean, default: true
26
26
 
27
- attr_accessor :text
27
+ attr_reader :text
28
28
 
29
29
  # Returns an array with one or more elements
30
30
  def to_a
31
31
  [ super, text.to_a ].reject(&:empty?)
32
32
  end
33
33
 
34
+ def text=(txt)
35
+ if txt.is_a? String
36
+ @text = EfoNelfo::V40::Order::Text.new text: txt
37
+ else
38
+ @text = txt
39
+ end
40
+ end
41
+
34
42
  end
35
43
 
36
44
  end
@@ -61,14 +61,25 @@ module EfoNelfo
61
61
  property :seller_country, alias: :SLandK, limit: 2
62
62
 
63
63
  def initialize(*args)
64
- super
65
64
  @lines = EfoNelfo::Array.new
65
+ super
66
66
  end
67
67
 
68
68
  def add(post_type)
69
69
  case
70
- when post_type.is_a?(Order::Line) then add_order_line(post_type)
71
- when post_type.is_a?(Order::Text) then add_text_to_order_line(post_type)
70
+ when post_type.is_a?(Order::Line)
71
+ add_order_line(post_type)
72
+ when post_type.is_a?(Order::Text)
73
+ add_text_to_order_line(post_type)
74
+ when post_type.is_a?(Hash)
75
+ add_order_line(EfoNelfo::V40::Order::Line.new(post_type))
76
+ end
77
+ end
78
+
79
+ def lines=(values)
80
+ @lines = EfoNelfo::Array.new
81
+ values.each do |item|
82
+ add item
72
83
  end
73
84
  end
74
85
 
@@ -88,7 +99,7 @@ module EfoNelfo
88
99
 
89
100
  # Appends a order line to the order
90
101
  def add_order_line(line)
91
- line.index = lines.count + 1
102
+ line.index = lines.size + 1
92
103
  lines << line
93
104
  end
94
105
 
@@ -1,3 +1,3 @@
1
1
  module EfoNelfo
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -27,6 +27,44 @@ describe EfoNelfo do
27
27
 
28
28
  end
29
29
 
30
+ describe "assign via hash" do
31
+ let(:json) {
32
+ { customer_id: "123",
33
+ order_number: "abc-123-efg",
34
+ seller_warehouse: "Somewhere",
35
+ label: "Some label",
36
+ lines: [
37
+ { item_type: 1, order_number: "12345", item_name: "Foo", price_unit: "NOK" },
38
+ { item_type: 1, order_number: "12345", item_name: "Bar", price_unit: "SEK", text: "This is freetext"},
39
+ ]
40
+ }
41
+ }
42
+ let(:order) { EfoNelfo::V40::Order.new json }
43
+
44
+ it "creates an order" do
45
+ order.must_be_instance_of EfoNelfo::V40::Order
46
+ end
47
+
48
+ it "assigns attributes" do
49
+ order.order_number.must_equal "abc-123-efg"
50
+ order.seller_warehouse.must_equal "Somewhere"
51
+ end
52
+
53
+ it "assigns order lines" do
54
+ order.lines.size.must_equal 2
55
+ order.lines[0].index.must_equal 1
56
+ order.lines[1].index.must_equal 2
57
+ order.lines[1].item_name.must_equal "Bar"
58
+ end
59
+
60
+ it "adds text to order lines" do
61
+ order.lines.first.text.must_be_nil
62
+ order.lines[1].text.must_be_instance_of EfoNelfo::V40::Order::Text
63
+ order.lines[1].text.to_s.must_equal "This is freetext"
64
+ end
65
+
66
+ end
67
+
30
68
  describe ".parse" do
31
69
 
32
70
  it "parses CSV and does the same as .load" do
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: 0.0.3
4
+ version: 0.0.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: 2013-02-25 00:00:00.000000000 Z
11
+ date: 2013-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -171,3 +171,4 @@ test_files:
171
171
  - spec/samples/B650517.032.csv
172
172
  - spec/samples/V4_varefil.csv
173
173
  - spec/spec_helper.rb
174
+ has_rdoc: