Sha256: b8f48bc4320e8ccff6bbb2a8d269517ff232523db3fbcc14a67e84c4be739f70

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Noticent
  module Definitions
    class ProductGroup

      attr_reader :products

      def initialize(config)
        @config = config
        @products = {}
      end

      def to(name)
        raise BadConfiguration, 'product name should be a symbol' unless name.is_a? Symbol
        raise BadConfiguration, "product #{name} is already in the list" if @products[name]
        raise BadConfiguration, "product #{name} is not defined. Use products to define it first" unless @config.products[name]

        @products[name] = @config.products[name]
      end

      def not_to(name)
        raise BadConfiguration, 'product name should be a symbol' unless name.is_a? Symbol
        raise BadConfiguration, "product #{name} is not defined. Use products to define it first" unless @config.products[name]

        # include all products, except the one named
        @config.products.each { |k, v| @products[k] = v unless k == name }
      end

      def count
        @products.count
      end

      def keys
        @products.keys
      end

      def values
        @products.values
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
noticent-0.0.6 lib/noticent/definitions/product_group.rb
noticent-0.0.5 lib/noticent/definitions/product_group.rb
noticent-0.0.4 lib/noticent/definitions/product_group.rb
noticent-0.0.3 lib/noticent/definitions/product_group.rb
noticent-0.0.2 lib/noticent/definitions/product_group.rb
noticent-0.0.1 lib/noticent/definitions/product_group.rb
noticent-0.0.1.pre.pre lib/noticent/definitions/product_group.rb