Sha256: e735ab855ac2678a18600283fe9982403d62e4eaf696f415e7d0d1ba91c101cd

Contents?: true

Size: 612 Bytes

Versions: 1

Compression:

Stored size: 612 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.1 lib/warehouse/random.rb