-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodules.rb
40 lines (36 loc) · 1.1 KB
/
modules.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
module Logic
# Description: Will add a new location or category to the database.
# Params:
# + name: String
def add(name)
DATABASE.execute("INSERT INTO #{@loc_cat} (name) VALUES ('#{name}')")
end
#Description: list all categories or locations
def list_all
DATABASE.execute("SELECT * FROM #{@loc_cat}")
end
#Description: list individual category or location by ID
#Params:
#+ value: Integer, ID of category or location
#Returns: An array containing a hash.
def list_one(value)
DATABASE.execute("SELECT * FROM #{@loc_cat} WHERE id = #{value}")
end
#Description: delete a category by id or name from the database.
#Params:
#+ value: String or Integer
def delete(value)
if value.is_a?(Integer)
DATABASE.execute("DELETE FROM #{@loc_cat} WHERE id = #{value}")
else
DATABASE.execute("DELETE FROM #{@loc_cat} WHERE name = '#{value}'")
end
end
#Description: update a category name by id
#Params:
#+ name: String, New name of category or location
#+ id: Integer
def update(name,id)
DATABASE.execute("UPDATE #{@loc_cat} SET name = '#{name}' WHERE id = #{id}")
end
end