Sha256: 6de0a469a31acfbd78e9f41348572f03a529ea3553d5780c5e6c43b9ac869865
Contents?: true
Size: 1.07 KB
Versions: 2
Compression:
Stored size: 1.07 KB
Contents
module Stockman module Logic class Kit class StockLevelsCollection include Enumerable attr_reader :kit_id def initialize(kit_id) @kit_id = kit_id.to_i 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 def each stock_levels.each{ |stock_level| yield stock_level } end def empty? stock_levels.empty? end def contents @contents ||= ContentsCollection.new(kit_id) end def stock_levels @stock_levels ||= load_stock_levels end def warehouse_ids @warehouse_ids ||= contents.map(&:warehouse_ids).flatten.uniq end private def load_stock_levels warehouse_ids.inject([]) do |memo, warehouse_id| memo << StockLevel.new(contents, 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/kit/stock_levels_collection.rb |
stockman-logic-0.1.0 | lib/stockman/logic/kit/stock_levels_collection.rb |