Sha256: 277c6c2aed4caafc504e5fd1b62c02d2dbc5205783b58640252c1fa5d004780a

Contents?: true

Size: 807 Bytes

Versions: 8

Compression:

Stored size: 807 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

      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

8 entries across 8 versions & 1 rubygems

Version Path
xsys-0.0.8 lib/xsys/model/product.rb
xsys-0.0.7 lib/xsys/model/product.rb
xsys-0.0.6 lib/xsys/model/product.rb
xsys-0.0.5 lib/xsys/model/product.rb
xsys-0.0.4 lib/xsys/model/product.rb
xsys-0.0.3 lib/xsys/model/product.rb
xsys-0.0.2 lib/xsys/model/product.rb
xsys-0.0.1 lib/xsys/model/product.rb