Class: CompareSupermarkets::Supermarket
- Inherits:
-
Object
- Object
- CompareSupermarkets::Supermarket
- Defined in:
- lib/compare_supermarkets/supermarket.rb
Direct Known Subclasses
Constant Summary collapse
- @@all =
[]
- @@products =
[]
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #add_product ⇒ Object
-
#initialize(name = nil) ⇒ Supermarket
constructor
A new instance of Supermarket.
Constructor Details
#initialize(name = nil) ⇒ Supermarket
Returns a new instance of Supermarket.
7 8 9 10 |
# File 'lib/compare_supermarkets/supermarket.rb', line 7 def initialize(name=nil) @name = name @@all << self end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/compare_supermarkets/supermarket.rb', line 2 def name @name end |
Class Method Details
.all ⇒ Object
12 13 14 |
# File 'lib/compare_supermarkets/supermarket.rb', line 12 def self.all @@all end |
.all_products ⇒ Object
16 17 18 |
# File 'lib/compare_supermarkets/supermarket.rb', line 16 def self.all_products @@products end |
.clear_all ⇒ Object
24 25 26 |
# File 'lib/compare_supermarkets/supermarket.rb', line 24 def self.clear_all @@all.clear end |
.products ⇒ Object
20 21 22 |
# File 'lib/compare_supermarkets/supermarket.rb', line 20 def self.products CompareSupermarkets::Product.all.select{|product| product.supermarket == self} end |
Instance Method Details
#add_product ⇒ Object
28 29 30 31 32 33 |
# File 'lib/compare_supermarkets/supermarket.rb', line 28 def add_product if @dollar_value != "0" && @cent_value != "0" new_product = CompareSupermarkets::Product.new(@supermarket, @name, @price, @unit_size, @url, @dollar_value, @cent_value) @@products << new_product end end |