Class: FindDeals::Deal

Inherits:
Object
  • Object
show all
Defined in:
lib/find_deals/deals.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: nil, url: nil, location: nil, price: 0, promotion: 0, about: nil, category_id: 1, city_id: 1) ⇒ Deal

Returns a new instance of Deal.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/find_deals/deals.rb', line 6

def initialize (title: nil, url: nil, location: nil, price: 0, promotion: 0, about: nil, category_id: 1, city_id: 1)
    @@all << self
    @title = title
    @location = location
    @url = url
    @price = price
    @promotion = promotion 
    @about = about
    @category_id = category_id
    @city_id = city_id
end

Instance Attribute Details

#aboutObject

Returns the value of attribute about.



2
3
4
# File 'lib/find_deals/deals.rb', line 2

def about
  @about
end

#category_idObject

Returns the value of attribute category_id.



2
3
4
# File 'lib/find_deals/deals.rb', line 2

def category_id
  @category_id
end

#city_idObject

Returns the value of attribute city_id.



2
3
4
# File 'lib/find_deals/deals.rb', line 2

def city_id
  @city_id
end

#locationObject

Returns the value of attribute location.



2
3
4
# File 'lib/find_deals/deals.rb', line 2

def location
  @location
end

#priceObject

Returns the value of attribute price.



2
3
4
# File 'lib/find_deals/deals.rb', line 2

def price
  @price
end

#promotionObject

Returns the value of attribute promotion.



2
3
4
# File 'lib/find_deals/deals.rb', line 2

def promotion
  @promotion
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/find_deals/deals.rb', line 2

def title
  @title
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/find_deals/deals.rb', line 2

def url
  @url
end

Class Method Details

.allObject



18
19
20
# File 'lib/find_deals/deals.rb', line 18

def self.all
    @@all
end

.reset_allObject



55
56
57
# File 'lib/find_deals/deals.rb', line 55

def self.reset_all
    @@all.clear
end

Instance Method Details



22
23
24
25
26
27
28
# File 'lib/find_deals/deals.rb', line 22

def print
    puts "===================================================================="
        puts "#{self.title.upcase}"
        puts "#{self.location}"
        puts "$#{self.price.to_i} - UP TO #{self.promotion.to_i}% OFF"
    puts "===================================================================="
end


30
31
32
33
34
35
36
37
38
# File 'lib/find_deals/deals.rb', line 30

def print_about_details
    puts "===================================================================="
    puts "#{self.title.upcase}"
    puts "===================================================================="
    puts "#{self.about}"
    puts ""
    puts "BUY NOW AT #{self.url}"
    puts "===================================================================="
end

#save(user_id) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/find_deals/deals.rb', line 40

def save(user_id)
    SavedDeals.find_or_create_by(
        title: self.title, 
        location: self.location, 
        url: self.url, 
        price: self.price, 
        promotion: self.promotion, 
        about: self.about, 
        category_id: self.category_id, 
        city_id: self.city_id,
        user_id: user_id
    )
   
end