class BuyerAPI
Public Class Methods
buy()
click to toggle source
# File lib/BuyerAPI.rb, line 14 def self.buy puts "\n\tEnter the details of product you want to buy ('q' to quit): " product_id = get_number("ID") product = ProductAPI.search_id(product_id) if !product puts "Product doesn't exist" elsif @@money < product[:price] puts "Insufficient funds to make purchase!" elsif product[:quantity].to_i < 1 puts "Product out of stock!" else ProductAPI.update(product[:id], :quantity, product[:quantity] - 1) @@money -= product[:price] transcation = { product_name: product[:name], buyer_name: @@name, buyer_cc_details: @@cc_details, timestamp: Time.now.to_s, amount_paid: product[:price] } TranscationAPI.record(transcation) puts "\n\tPurchase successful, current amount left: #{@@money}" end end
set_cc_details(cc)
click to toggle source
# File lib/BuyerAPI.rb, line 48 def self.set_cc_details(cc) @@cc_details = cc end
set_money(m)
click to toggle source
# File lib/BuyerAPI.rb, line 44 def self.set_money(m) @@money = m end
set_name(n)
click to toggle source
# File lib/BuyerAPI.rb, line 40 def self.set_name(n) @@name = n end