warehouse_items 0.3.0 → 1.0.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
- SHA1:
3
- metadata.gz: 4b89d5f0f304a6888274847e417e27c74fae9444
4
- data.tar.gz: cbe617fabef2b617691855d6d629bd00e8d27bc2
2
+ SHA256:
3
+ metadata.gz: ffa41dc7cfb37c0cafee84925e709e012391a3bda4728bf529bee62091c1e1f5
4
+ data.tar.gz: 81884116cb317e6510f8b72e45a9e883672480171dcd428f7f23074a51992153
5
5
  SHA512:
6
- metadata.gz: 31033a056576526da3ba4b74399b46189af5d745cb522b57e1b8383b20e9ad247e0aef131b0ac47e94b2842650200d437a949a17c780674e6d441868f42ad64f
7
- data.tar.gz: 9a23c3aed31ac2b1d0ea25f64ffc0ad85932fee7bba92068d808883a2959d1c6e2b58c812be2d44a73c726935cfecacb5482cce7a94cf55ac69d4e7e2abf3664
6
+ metadata.gz: 3b805174c9972f0f23cd470a08762fc9a1505483e24cb07bb755f008d8edde1bd6cea28f8fcdf3e70e31a888a6cf04b9c64efc229f35a5648136acfc4e9ea46f
7
+ data.tar.gz: 9cbb09b6c45a804e5bf6bb2ea9567affa9b935755d6a0f0f121cc8c4626b383457a23c45b779ec1bc26ac14f4e98b43c1e1ca0c164b1337dba85069653c36328
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.*.sw?
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.7
data/README.md CHANGED
@@ -1,25 +1,25 @@
1
1
  # Warehouse::Item
2
2
 
3
3
  ```ruby
4
- @item1 = Warehouse::Item.new('迷黑', '迷黑', 3, 250)
4
+ @item1 = Warehouse::Item::Code.new('迷黑', '迷黑', 3, 250)
5
5
  ```
6
6
 
7
7
  # Warehouse::Random
8
8
 
9
9
  ```ruby
10
- @item1 = Warehouse::Item.new('迷黑', '迷黑', nil, 250)
11
- @item2 = Warehouse::Item.new('迷黃', '迷黃', nil, 250)
12
- @item3 = Warehouse::Item.new('迷綠', '迷綠', nil, 250)
13
- @random_item = Warehouse::Random.new([@item1, @item2, @item3], 4)
10
+ @item1 = Warehouse::Item::Code.new('迷黑', '迷黑', nil, 250)
11
+ @item2 = Warehouse::Item::Code.new('迷黃', '迷黃', nil, 250)
12
+ @item3 = Warehouse::Item::Code.new('迷綠', '迷綠', nil, 250)
13
+ @random_item = Warehouse::Item::Random.new([@item1, @item2, @item3], 4)
14
14
  @list = @random_item.fetch! # (Warehouse::List)
15
15
  ```
16
16
 
17
17
  # Warehouse::List
18
18
 
19
19
  ```ruby
20
- @item1 = Warehouse::Item.new('迷黑', '迷黑', 1, 250)
21
- @item2 = Warehouse::Item.new('迷黃', '迷黃', 1, 250)
22
- @item3 = Warehouse::Item.new('迷綠', '迷綠', 1, 250)
20
+ @item1 = Warehouse::Item::Code.new('迷黑', '迷黑', 1, 250)
21
+ @item2 = Warehouse::Item::Code.new('迷黃', '迷黃', 1, 250)
22
+ @item3 = Warehouse::Item::Code.new('迷綠', '迷綠', 1, 250)
23
23
  @list = Warehouse::List.new([@item1, @item2, @item3])
24
24
 
25
25
  # 所有數量變兩倍 (會解壓縮 RandomItem)
@@ -1,6 +1,16 @@
1
1
  module Warehouse
2
2
  module Item
3
- Code = Struct.new(:code, :title, :qty, :price) do
3
+ Code = Struct.new(:code, :title, :qty, :price, :barcode, :code_2, :title_en) do
4
+
5
+ def self.build(fragment)
6
+ qty = fragment["qty"].nil? ? 0 : fragment["qty"].to_i
7
+ Code.new(fragment["code"], fragment["title"], qty, fragment["price"].to_i,
8
+ fragment["barcode"], fragment["code_2"], fragment["title_en"])
9
+ end
10
+
11
+ def is_free?
12
+ price == 0
13
+ end
4
14
 
5
15
  def barcode?
6
16
  false
@@ -26,12 +36,16 @@ module Warehouse
26
36
  {
27
37
  'code' => code,
28
38
  'title' => title,
29
- 'qty' => qty
39
+ 'qty' => qty,
40
+ 'price' => price,
41
+ 'barcode' => barcode,
42
+ 'code_2' => code_2,
43
+ 'title_en' => title_en
30
44
  }
31
45
  end
32
46
 
33
47
  def deep_dup
34
- self.class.new(code, title, qty, price)
48
+ self.class.new(code, title, qty, price, barcode, code_2, title_en)
35
49
  end
36
50
 
37
51
  # 給 form 用的
@@ -23,7 +23,8 @@ module Warehouse
23
23
  random_items = {}
24
24
  (1..qty).each do
25
25
  item = items.sample
26
- random_items[item.code] ||= Warehouse::Item::Code.new(item.code, item.title, 0, item.price)
26
+ random_items[item.code] ||= Warehouse::Item::Code.new(item.code, item.title, 0, item.price,
27
+ item.barcode, item.code_2, item.title_en)
27
28
  random_items[item.code].qty += 1
28
29
  end
29
30
  Warehouse::List.new(random_items.values)
@@ -1,3 +1,3 @@
1
1
  module Warehouse
2
- VERSION = "0.3.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/warehouse.rb CHANGED
@@ -8,5 +8,5 @@ require "warehouse/item/random"
8
8
  require "warehouse/list"
9
9
 
10
10
  module Warehouse
11
-
11
+
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warehouse_items
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddie Li
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-17 00:00:00.000000000 Z
11
+ date: 2022-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".ruby-version"
91
92
  - ".travis.yml"
92
93
  - Gemfile
93
94
  - Gemfile.lock
@@ -122,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements: []
125
- rubyforge_project:
126
- rubygems_version: 2.4.8
126
+ rubygems_version: 3.0.3.1
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: warehouse_items wrapper & value objects