Sha256: 7bd0fa2e5892fb4b1c8a5bb797d1bf6eab7b0247b46294c6ad6c0a4685947dfa

Contents?: true

Size: 610 Bytes

Versions: 1

Compression:

Stored size: 610 Bytes

Contents

class Warehouse::Random < Struct.new(:items, :qty)

  attr_accessor :code, :title, :price

  def type
    'random'
  end

  def random?
    true
  end

  def single?
    false
  end

  def fetch
    @fetch ||= fetch!
  end

  def fetch!
    random_items = {}
    (1..qty).each do
      item = items.sample
      random_items[item.code] = Warehouse::Item.new(item.code, item.title, 0, item.price)
      random_items[item.code].qty += 1
    end
    Warehouse::List.new(random_items.values)
  end

  def persisted?; end

  def deep_dup
    Warehouse::Random.new(items.map { |item| item.deep_dup }, qty)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
warehouse_items-0.1.0 lib/warehouse/random.rb