Sha256: 6281d4b780b8b273d44c17e94a39d67335cbed92fe973dcdfccae8d37a9087d5

Contents?: true

Size: 868 Bytes

Versions: 1

Compression:

Stored size: 868 Bytes

Contents

module Warehouse
  module Item
    Random = Struct.new(:items, :qty) do
      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::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

      def persisted?; end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
warehouse_items-1.0.0 lib/warehouse/item/random.rb