/
gui.rb
109 lines (80 loc) · 2.98 KB
/
gui.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
102
103
104
105
106
107
108
109
require 'rubygems'
require 'usefuldb/utilities'
module UsefulDB
class GUI
class << self
attr_accessor
# Search the database
def search(args, log)
log.debug "Loading the database"
UsefulDB.dbLoad(log)
log.debug "Launching UsefulDB::UsefulUtils.search"
args.each {|i| puts "\n" + UsefulDB::UsefulUtils.search(i, log)}
end
# List entries in the database
def list(log)
log.debug "Loading the database"
UsefulDB.dbLoad(log)
log.debug "Launching UsefulDB::UsefulUtils.list"
index = 0
listing = UsefulDB::UsefulUtils.list(log)
listing.each do |i|
puts "Element: " + index.to_s
index += 1
msg = ''
msg += "- Tags: " + UsefulDB::UsefulUtils.array_to_s(i["tag"]) + "\n"
puts msg
puts "- Value: " + i["value"]
puts "- Description: " + i["description"] + "\n\n##\n"
end
log.info "Number of entries in the database is: " + UsefulDB::UsefulUtils.count(log).to_s
end
# Remove an entry from the database
def remove(log)
log.info "Printing out the list of database entries\n"
list(log)
puts "Enter the number of the element from the list above which you want to delete"
value = STDIN.gets
log.debug value
begin
UsefulDB.remove(value.to_i, log)
log.info "Entry removed"
UsefulDB.dbSave(log)
log.info "Saving database"
rescue KeyOutOfBounds => e
puts e.message + "\nexiting."
log.fatal e.message
exit()
end
end
# Add element to the database
def add(log)
UsefulDB.dbLoad(log)
puts "Please enter the comma separated search tags like the following:"
log.info "eg:\nterm1, term2, term3\n\n"
begin
tags = ((STDIN.gets).strip).split(', ')
log.debug tags.inspect
puts "Please enter the value you wish to store for this database entry:"
value = (STDIN.gets).strip
log.debug value
puts "Please enter a description for this entry: "
description = (STDIN.gets).strip
log.debug description
entry = {"tag" => tags, "value" => value, "description" => description}
log.info "Storing the following in the database:"
log.info "Search tags: " + UsefulDB::UsefulUtils.array_to_s(tags)
log.info "Entry Value: " + value
log.info "Description: " + description
UsefulDB.add(entry, log)
UsefulDB.dbSave(log)
log.info "Saving database"
rescue Exception => e
puts e.message
log.fatal e.message
exit
end
end
end
end
end