Class: Warehouse::Item::Random
- Inherits:
-
Struct
- Object
- Struct
- Warehouse::Item::Random
- Defined in:
- lib/warehouse/item/random.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#items ⇒ Object
Returns the value of attribute items.
-
#price ⇒ Object
Returns the value of attribute price.
-
#qty ⇒ Object
Returns the value of attribute qty.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #deep_dup ⇒ Object
- #fetch ⇒ Object
- #fetch! ⇒ Object
- #persisted? ⇒ Boolean
- #random? ⇒ Boolean
- #single? ⇒ Boolean
- #type ⇒ Object
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
4 5 6 |
# File 'lib/warehouse/item/random.rb', line 4 def code @code end |
#items ⇒ Object
Returns the value of attribute items
3 4 5 |
# File 'lib/warehouse/item/random.rb', line 3 def items @items end |
#price ⇒ Object
Returns the value of attribute price.
4 5 6 |
# File 'lib/warehouse/item/random.rb', line 4 def price @price end |
#qty ⇒ Object
Returns the value of attribute qty
3 4 5 |
# File 'lib/warehouse/item/random.rb', line 3 def qty @qty end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/warehouse/item/random.rb', line 4 def title @title end |
Instance Method Details
#deep_dup ⇒ Object
35 36 37 |
# File 'lib/warehouse/item/random.rb', line 35 def deep_dup Warehouse::Item::Random.new(items.map { |item| item.deep_dup }, qty) end |
#fetch ⇒ Object
18 19 20 |
# File 'lib/warehouse/item/random.rb', line 18 def fetch @fetch ||= fetch! end |
#fetch! ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/warehouse/item/random.rb', line 22 def fetch! random_items = {} (1..qty).each do item = items.sample random_items[item.code] ||= Warehouse::Item::Code.new(item.code, item.title, 0, item.price, item., item.code_2, item.title_en) random_items[item.code].qty += 1 end Warehouse::List.new(random_items.values) end |
#persisted? ⇒ Boolean
33 |
# File 'lib/warehouse/item/random.rb', line 33 def persisted?; end |
#random? ⇒ Boolean
10 11 12 |
# File 'lib/warehouse/item/random.rb', line 10 def random? true end |
#single? ⇒ Boolean
14 15 16 |
# File 'lib/warehouse/item/random.rb', line 14 def single? false end |
#type ⇒ Object
6 7 8 |
# File 'lib/warehouse/item/random.rb', line 6 def type 'random' end |