Class: UsefulDB::GUI
- Inherits:
-
Object
- Object
- UsefulDB::GUI
- Defined in:
- lib/usefuldb/gui.rb
Class Method Summary collapse
-
.add(log) ⇒ Object
Add element to the database.
-
.list(log) ⇒ Object
List entries in the database.
-
.remove(log) ⇒ Object
Remove an entry from the database.
-
.search(args, log) ⇒ Object
Search the database.
Class Method Details
.add(log) ⇒ Object
Add element to the database
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 |
# File 'lib/usefuldb/gui.rb', line 68 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 = ((STDIN.gets).strip).split(', ') log.debug .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" => , "value" => value, "description" => description} log.info "Storing the following in the database:" log.info "Search tags: " + UsefulDB::UsefulUtils.array_to_s() 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. log.fatal e. exit end end |
.list(log) ⇒ Object
List entries in the database
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/usefuldb/gui.rb', line 22 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(log) ⇒ Object
Remove an entry from the database
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/usefuldb/gui.rb', line 45 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. + "\nexiting." log.fatal e. exit() end end |
.search(args, log) ⇒ Object
Search the database
12 13 14 15 16 17 18 |
# File 'lib/usefuldb/gui.rb', line 12 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 |