Class: Warehouse::Item::Random

Inherits:
Struct
  • Object
show all
Defined in:
lib/warehouse/item/random.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject

Returns the value of attribute code.



4
5
6
# File 'lib/warehouse/item/random.rb', line 4

def code
  @code
end

#itemsObject

Returns the value of attribute items

Returns:

  • (Object)

    the current value of items



3
4
5
# File 'lib/warehouse/item/random.rb', line 3

def items
  @items
end

#priceObject

Returns the value of attribute price.



4
5
6
# File 'lib/warehouse/item/random.rb', line 4

def price
  @price
end

#qtyObject

Returns the value of attribute qty

Returns:

  • (Object)

    the current value of qty



3
4
5
# File 'lib/warehouse/item/random.rb', line 3

def qty
  @qty
end

#titleObject

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_dupObject



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

#fetchObject



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.barcode, item.code_2, item.title_en)
    random_items[item.code].qty += 1
  end
  Warehouse::List.new(random_items.values)
end

#persisted?Boolean

Returns:

  • (Boolean)


33
# File 'lib/warehouse/item/random.rb', line 33

def persisted?; end

#random?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/warehouse/item/random.rb', line 10

def random?
  true
end

#single?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/warehouse/item/random.rb', line 14

def single?
  false
end

#typeObject



6
7
8
# File 'lib/warehouse/item/random.rb', line 6

def type
  'random'
end