Class: Noticent::Definitions::ProductGroup
- Inherits:
-
Object
- Object
- Noticent::Definitions::ProductGroup
- Defined in:
- lib/noticent/definitions/product_group.rb
Instance Attribute Summary collapse
-
#products ⇒ Object
readonly
Returns the value of attribute products.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(config) ⇒ ProductGroup
constructor
A new instance of ProductGroup.
- #keys ⇒ Object
- #not_to(name) ⇒ Object
- #to(name) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(config) ⇒ ProductGroup
Returns a new instance of ProductGroup.
9 10 11 12 |
# File 'lib/noticent/definitions/product_group.rb', line 9 def initialize(config) @config = config @products = {} end |
Instance Attribute Details
#products ⇒ Object (readonly)
Returns the value of attribute products.
7 8 9 |
# File 'lib/noticent/definitions/product_group.rb', line 7 def products @products end |
Instance Method Details
#count ⇒ Object
30 31 32 |
# File 'lib/noticent/definitions/product_group.rb', line 30 def count @products.count end |
#keys ⇒ Object
34 35 36 |
# File 'lib/noticent/definitions/product_group.rb', line 34 def keys @products.keys end |
#not_to(name) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/noticent/definitions/product_group.rb', line 22 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 |
#to(name) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/noticent/definitions/product_group.rb', line 14 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 |
#values ⇒ Object
38 39 40 |
# File 'lib/noticent/definitions/product_group.rb', line 38 def values @products.values end |