Sha256: e389a9a25af448b87eecec26445566230f9ecf3cb8400896e330d37294e90ba7

Contents?: true

Size: 631 Bytes

Versions: 3

Compression:

Stored size: 631 Bytes

Contents

module ShoppingCart
  class OrdersFilter
    FILTERS = {
      'in_queue' => :in_queue,
      'in_delivery' => :in_delivery,
      'delivered' => :delivered,
      'canceled' => :canceled
    }.freeze

    def initialize(orders:, params:)
      @orders = orders
      @params = params
    end

    def call
      return send(FILTERS[@params[:filter]]) if FILTERS[@params[:filter]]

      @orders
    end

    private

    def in_queue
      @orders.in_queue
    end

    def in_delivery
      @orders.in_delivery
    end

    def delivered
      @orders.delivered
    end

    def canceled
      @orders.canceled
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
loker-shopping-cart-0.1.3 app/queries/shopping_cart/orders_filter.rb
loker-shopping-cart-0.1.2 app/queries/shopping_cart/orders_filter.rb
loker-shopping-cart-0.1.1 app/queries/shopping_cart/orders_filter.rb