class FindDeals::Deal
Attributes
about[RW]
category_id[RW]
city_id[RW]
location[RW]
price[RW]
promotion[RW]
title[RW]
url[RW]
Public Class Methods
all()
click to toggle source
# File lib/find_deals/deals.rb, line 18 def self.all @@all end
new(title: nil, url: nil, location: nil, price: 0, promotion: 0, about: nil, category_id: 1, city_id: 1)
click to toggle source
# 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
reset_all()
click to toggle source
# File lib/find_deals/deals.rb, line 55 def self.reset_all @@all.clear end
Public Instance Methods
print()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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