bbmb 2.0.9 → 2.1.0

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: 3dbe4ee9956c4b592fa58f23029b197bfddaab36
4
- data.tar.gz: 7bcba109d2eb190ec0996bb4c6bba86ba201c174
3
+ metadata.gz: a3b93d7a7e2800135e52951c1e54b67b04bb4b0a
4
+ data.tar.gz: 61a41c9428776513b2a11037880e421b6f5eb3a5
5
5
  SHA512:
6
- metadata.gz: a0d55dbfa2322c13e3611ced131d1ee6184e21441c297ae78e828e1f708b9a704fe3f750caa86ff04f336e014e091cbbe4a200d2cb8772a8ee7fe8aff1fd32fd
7
- data.tar.gz: dd46d10aa2c1dc52ddd01569c178bb755ae12eb43570fb8366397e1bbd6e195aa1cdd60e7d1ddc237e1744b95268a1c770ab7f330e85cb96e5056c1b6d0f7a83
6
+ metadata.gz: aace6d576d08d5e9887da6a160f4dc0c08e6c4f2e066b18482d80a95c344c402771022b0afb6f065deaa6a9e5f893c9d71b0a16240261d90c6c1405a75b3dcf9
7
+ data.tar.gz: eeff85c50055ce4607c6b52dc901c1f3fa9c3e156b2cc4293ea5a00400940fea7c9715697460b979460ee47ec6878a3576c6fc128b91eff7d0a50521f159cc5e
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 2.1.0 / 19.08.2016
2
+
3
+ * Add ProductInfo#to_product utility method
4
+
1
5
  === 2.0.9 / 20.07.2016
2
6
 
3
7
  * Add EAN-Code as search target
@@ -62,12 +62,48 @@ class ProductInfo < Subject
62
62
  instance_variable_get("@l#{level}_qty")
63
63
  end
64
64
  end
65
- def to_info
66
- self
67
- end
65
+
68
66
  def ==(other)
69
67
  other.is_a?(ProductInfo) && @article_number == other.article_number
70
68
  end
69
+
70
+ def to_info
71
+ self
72
+ end
73
+
74
+ def to_product
75
+ convert_to(Product)
76
+ end
77
+
78
+ private
79
+
80
+ # Converts as new instance
81
+ #
82
+ # @param [Class] klass New class {Product|ProductInfo}
83
+ # @return [Array(Product,ProductInfo)] new instance
84
+ def convert_to(klass)
85
+ base_keys = %i{
86
+ backorder_date catalogue1 catalogue2 catalogue3
87
+ description ean13 expiry_date partner_index pcode status
88
+ }
89
+ keys = case klass.to_s
90
+ when 'BBMB::Model::Product'
91
+ base_keys
92
+ when 'BBMB::Model::ProductInfo'
93
+ base_keys += %i{
94
+ vat price
95
+ l1_qty l2_qty l3_qty l4_qty l5_qty l6_qty
96
+ l1_price l2_price l3_price l4_price l5_price l6_price
97
+ }
98
+ else
99
+ raise "Unknown class #{klass}"
100
+ end
101
+ obj = klass.new(@article_number)
102
+ keys.each { |key| obj.send("#{key}=", self.send(key)) }
103
+ obj.promotion = @promotion.dup if (@promotion && @promotion.current?)
104
+ obj.sale = @sale.dup if (@sale && @sale.current?)
105
+ obj
106
+ end
71
107
  end
72
108
  class Product < ProductInfo
73
109
  def backorder=(value)
@@ -81,18 +117,13 @@ class Product < ProductInfo
81
117
  def current_promo
82
118
  [@sale, @promotion].find { |promo| promo && promo.current? }
83
119
  end
120
+
121
+ def to_product
122
+ self
123
+ end
124
+
84
125
  def to_info
85
- info = ProductInfo.new(@article_number)
86
- [ :backorder_date, :catalogue1, :catalogue2, :catalogue3,
87
- :description, :ean13, :expiry_date, :partner_index, :pcode,
88
- :status, :l1_qty, :l2_qty, :l3_qty, :l4_qty, :l5_qty, :l6_qty, :vat,
89
- :price, :l1_price, :l2_price, :l3_price, :l4_price, :l5_price, :l6_price
90
- ].each { |key|
91
- info.send("#{key}=", self.send(key))
92
- }
93
- info.promotion = @promotion.dup if(@promotion && @promotion.current?)
94
- info.sale = @sale.dup if(@sale && @sale.current?)
95
- info
126
+ convert_to(ProductInfo)
96
127
  end
97
128
  end
98
129
  end
data/lib/bbmb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BBMB
2
- VERSION = '2.0.9'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -79,13 +79,29 @@ class TestProduct < Minitest::Test
79
79
  @product.l6_price = 16.50
80
80
  assert_equal(16.50, @product.price(6))
81
81
  end
82
- def test_info
82
+
83
+ def test_to_info
83
84
  info = @product.to_info
84
85
  assert_instance_of(ProductInfo, info)
85
86
  assert_equal('article_number', info.article_number)
86
- info1 = info.to_info
87
- assert_equal(info, info1)
87
+ assert_equal(info, info.to_info)
88
+ end
89
+
90
+ def test_to_product
91
+ product = @product.to_info.to_product
92
+ assert_instance_of(Product, product)
93
+ assert_equal('article_number', product.article_number)
94
+ assert_equal(product, product.to_product)
95
+ %w{
96
+ backorder_date catalogue1 catalogue2 catalogue3
97
+ description ean13 expiry_date partner_index pcode status
98
+ }.map do |attr|
99
+ assert_equal(@product.send(attr), product.send(attr))
100
+ end
101
+ assert_equal(@product.promotion, product.promotion)
102
+ assert_equal(@product.sale, product.sale)
88
103
  end
104
+
89
105
  def test_price_levels__no_promo
90
106
  @product.l1_qty = 1
91
107
  @product.l1_price = 10
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbmb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.9
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaomi Hatakeyama, Zeno R.R. Davatz, Niklaus Giger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-20 00:00:00.000000000 Z
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: odba
@@ -485,3 +485,4 @@ test_files:
485
485
  - test/util/test_server.rb
486
486
  - test/util/test_target_dir.rb
487
487
  - test/util/test_transfer_dat.rb
488
+ has_rdoc: