Class: FindDeals::Deal
- Inherits:
-
Object
- Object
- FindDeals::Deal
- Defined in:
- lib/find_deals/deals.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#about ⇒ Object
Returns the value of attribute about.
-
#category_id ⇒ Object
Returns the value of attribute category_id.
-
#city_id ⇒ Object
Returns the value of attribute city_id.
-
#location ⇒ Object
Returns the value of attribute location.
-
#price ⇒ Object
Returns the value of attribute price.
-
#promotion ⇒ Object
Returns the value of attribute promotion.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(title: nil, url: nil, location: nil, price: 0, promotion: 0, about: nil, category_id: 1, city_id: 1) ⇒ Deal
constructor
A new instance of Deal.
- #print ⇒ Object
- #print_about_details ⇒ Object
- #save(user_id) ⇒ Object
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
#about ⇒ Object
Returns the value of attribute about.
2 3 4 |
# File 'lib/find_deals/deals.rb', line 2 def about @about end |
#category_id ⇒ Object
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_id ⇒ Object
Returns the value of attribute city_id.
2 3 4 |
# File 'lib/find_deals/deals.rb', line 2 def city_id @city_id end |
#location ⇒ Object
Returns the value of attribute location.
2 3 4 |
# File 'lib/find_deals/deals.rb', line 2 def location @location end |
#price ⇒ Object
Returns the value of attribute price.
2 3 4 |
# File 'lib/find_deals/deals.rb', line 2 def price @price end |
#promotion ⇒ Object
Returns the value of attribute promotion.
2 3 4 |
# File 'lib/find_deals/deals.rb', line 2 def promotion @promotion end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/find_deals/deals.rb', line 2 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/find_deals/deals.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
18 19 20 |
# File 'lib/find_deals/deals.rb', line 18 def self.all @@all end |
.reset_all ⇒ Object
55 56 57 |
# File 'lib/find_deals/deals.rb', line 55 def self.reset_all @@all.clear end |
Instance Method Details
#print ⇒ Object
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 |
#print_about_details ⇒ Object
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 |