Sha256: aea626f26742df165b42f69ae17cb7b6d3c7a6743073f3cf870f882083166f9f

Contents?: true

Size: 599 Bytes

Versions: 1

Compression:

Stored size: 599 Bytes

Contents

require 'active_model'

module Rawbotz
  module Models
    class Stock
      include ActiveModel::Model # convenience

      def self.all_stock
        stock = {}
        RawgentoDB::Query.stock.each {|s| stock[s.product_id] = s.qty}
        stock
      end

      # Returns a map of product_id to RawgentoDB::ProductQty .
      def self.stock_for product_ids
        stock = {}
        # Find ruby idiomatic way to do that (probably map{}.to_h)
        RawgentoDB::Query.stock_for(product_ids).each do |s|
          stock[s.product_id] = s.qty
        end
        stock
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rawbotz-0.2.0 lib/rawbotz/models/stock.rb