Class: CompareSupermarkets::Supermarket

Inherits:
Object
  • Object
show all
Defined in:
lib/compare_supermarkets/supermarket.rb

Direct Known Subclasses

Coles, Woolworths

Constant Summary collapse

@@all =
[]
@@products =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/compare_supermarkets/supermarket.rb', line 2

def name
  @name
end

Class Method Details

.allObject



12
13
14
# File 'lib/compare_supermarkets/supermarket.rb', line 12

def self.all
    @@all
end

.all_productsObject



16
17
18
# File 'lib/compare_supermarkets/supermarket.rb', line 16

def self.all_products
    @@products
end

.clear_allObject



24
25
26
# File 'lib/compare_supermarkets/supermarket.rb', line 24

def self.clear_all
    @@all.clear
end

.productsObject



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_productObject



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