Sha256: 2cd850200c21b2c7a7037ebca2f4c3262af4f47e545754b30cb89a273061e75f

Contents?: true

Size: 888 Bytes

Versions: 9

Compression:

Stored size: 888 Bytes

Contents

module Xsys
  module Model
    class Product
      attr_accessor :id, :name, :cost, :active, :sellable, :list_price_1, :list_price_6,
        :list_price_35, :markup_1, :markup_6, :markup_35, :category, :provider, :stocks,
        :remaining_quantity, :sales, :value_added_tax, :list_price_1_date, :list_price_6_date,
        :list_price_35_date, :cost_date

      def initialize(attributes={})
        attributes.each do |k,v|
          if k == 'category'
            @category = ProductCategory.new(v)
          elsif k == 'provider'
            @provider = ProductProvider.new(v)
          elsif k == 'stocks'
            @stocks = v.map { |s| Stock.new(s) }
          else
            self.send("#{k}=", v)
          end
        end
      end

      def stock_in(shop_code)
        stocks.find { |s| s.shop_code.to_sym == shop_code.to_sym }.try(:quantity)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
xsys-0.0.17 lib/xsys/model/product.rb
xsys-0.0.16 lib/xsys/model/product.rb
xsys-0.0.15 lib/xsys/model/product.rb
xsys-0.0.14 lib/xsys/model/product.rb
xsys-0.0.13 lib/xsys/model/product.rb
xsys-0.0.12 lib/xsys/model/product.rb
xsys-0.0.11 lib/xsys/model/product.rb
xsys-0.0.10 lib/xsys/model/product.rb
xsys-0.0.9 lib/xsys/model/product.rb