-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.rb
101 lines (93 loc) · 2.31 KB
/
product.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Class: Category
#
# Models our Product objects that live within categories and shelves.
#
# Attributes:
# @name - String: Primary Key related to the shelves table of db.
# @shelf_id - Integer: Denotes what shelf the object belongs to.
# @category_id - Integer: Denotes what category the object belongs to.
# @description - String: Describes the product
# @price - Integer: Price in pennies
# @quantity - Integer: How many of the product are on the shelf
# @id - Integer: Primary Key related to the products table of db.
#
# Public Methods:
# .requirements
class Product
include DatabaseMethods
attr_accessor :name, :quantity, :shelf_id, :category_id,
:description, :price, :quantity, :id
def initialize(options)
@name = options["name"]
@shelf_id = options["shelf_id"]
@category_id = options["category_id"]
@description = options["description"]
@price = options["price"]
@quantity = options["quantity"]
@id = options["id"]
end
# # Public: #list_location_of
# # Prompts database for the shelf name of the product.
# #
# # Returns:
# # String: Name of the shelf the product is on.
# #
# # State Changes:
# # None
#
# def list_location_of
# loc = DATABASE.execute("SELECT name FROM shelves WHERE id = #{@shelf_id}")
# loc[0]["name"]
# end
#
# # Public: #update_location_of
# # Changes the shelf_id to new_loc
# #
# # Paramteres:
# #
# #
# # Returns:
# # String: Name of the shelf the product is on.
# #
# # State Changes:
# # None
#
# def update_location_of(new_loc)
# @shelf_id = new_loc
# save
# end
#
# def assign_new_category(new_category)
# @category_id = new_category
# save
# end
#
# def buy_product(amount)
# @quantity += amount
# save
# end
#
# def sell_product(amount)
# check = quantity
# unless check - amount < 0
# @quantity -= amount
# save
# end
# end
#
# def update_price(amount)
# @price = amount
# save
# end
# Public: .requirements
# Class method that returns the instance methods of a Product item minus @id.
#
# Returns:
# Array
#
# State Changes:
# None
def self.requirements
requirements = ["name", "shelf_id", "category_id", "description", "price", "quantity"]
end
end