class Seshbot::Packing::LineItem
:nodocs:
Attributes
price[RW]
quantity[RW]
sku_fragment[RW]
Public Class Methods
merge_line_items(items)
click to toggle source
# File lib/seshbot/packing/line_item.rb, line 30 def self.merge_line_items(items) result = Hash.new(0) # create a hash were the keys are sku_fragment, and the values are the summed quantities items.each do |item| result[item.sku_fragment] += item.quantity end result.delete_if { |k,v| v == 0 } result.map { |sku_fragment, quantity| LineItem.new(sku_fragment, quantity) } end
new(sku_fragment, quantity, price=0)
click to toggle source
# File lib/seshbot/packing/line_item.rb, line 9 def initialize(sku_fragment, quantity, price=0) raise 'SKU fragment must be a string' if sku_fragment.class != String raise 'Quantity must be an integer' if quantity.class != Integer @sku_fragment = sku_fragment @quantity = quantity @price = price end
summarise(items)
click to toggle source
# File lib/seshbot/packing/line_item.rb, line 22 def self.summarise(items) "#{items.map(&:to_s)}" end
total_quantity(items)
click to toggle source
# File lib/seshbot/packing/line_item.rb, line 26 def self.total_quantity(items) items.map { |i| i.quantity }.sum end
Public Instance Methods
to_s()
click to toggle source
# File lib/seshbot/packing/line_item.rb, line 18 def to_s "#{quantity}x#{sku_fragment}" end