Sha256: 84f5ba26594e34fe5e75c06a408c9d9b23f4b960f9c1fb0c02e23c8ceb38707c
Contents?: true
Size: 1.17 KB
Versions: 2
Compression:
Stored size: 1.17 KB
Contents
module Stockman module Logic class Product class StockLevelsCollection include Enumerable attr_reader :product_id def initialize(product_id) @product_id = product_id.to_i end def sellables @sellables ||= SellablesCollection.new(product_id) end def stock_levels @stock_levels ||= load_stock_levels end def warehouse_ids @warehouse_ids ||= load_warehouse_ids end def each stock_levels.each{ |stock_level| yield stock_level } end def empty? stock_levels.empty? end def [](warehouse_id) find_by_warehouse(warehouse_id) end def find_by_warehouse(warehouse_id) stock_levels.detect{ |stock_level| stock_level.warehouse_id == warehouse_id } end private def load_warehouse_ids sellables.map(&:warehouse_ids).flatten.uniq end def load_stock_levels warehouse_ids.inject([]) do |memo, warehouse_id| memo << StockLevel.new(sellables, warehouse_id) end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stockman-logic-0.1.1 | lib/stockman/logic/product/stock_levels_collection.rb |
stockman-logic-0.1.0 | lib/stockman/logic/product/stock_levels_collection.rb |