Class: UI
- Inherits:
-
Object
- Object
- UI
- Defined in:
- lib/ruby_doc/cli/ui.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#counter ⇒ Object
readonly
Properties===================.
Class Method Summary collapse
- .browse_control(identifier, page) ⇒ Object
- .browse_error(input, identifier, page) ⇒ Object
- .browse_list(page, identifier) ⇒ Object
- .browse_list_error(page) ⇒ Object
- .browse_menu(page) ⇒ Object
- .clear ⇒ Object
-
.cyanH(str) ⇒ Object
red highlight.
-
.display_class(doc, view = "short") ⇒ Object
——————-docs———————–.
- .display_class_control(doc) ⇒ Object
- .display_class_error(doc) ⇒ Object
- .display_class_menu(doc) ⇒ Object
- .display_method(doc) ⇒ Object
- .display_method_control(doc) ⇒ Object
- .display_method_error ⇒ Object
- .display_method_menu ⇒ Object
- .favorites_error ⇒ Object
-
.favorites_list ⇒ Object
——————-lists———————-.
- .favorites_list_control(list) ⇒ Object
-
.favorites_message ⇒ Object
——————messages——————–.
- .last_page_menu(page) ⇒ Object
-
.learn_more ⇒ Object
—————–learn more——————-.
- .list_control(matches) ⇒ Object
- .list_error(matches) ⇒ Object
- .list_menu(matches) ⇒ Object
-
.loading_animation ⇒ Object
Goes inside iterator - last line.
-
.loading_message ⇒ Object
Goes above iterator.
-
.main_control ⇒ Object
Control=====================.
-
.main_error ⇒ Object
Error======================.
-
.main_menu(from = "default") ⇒ Object
Menus======================.
- .method_list(doc) ⇒ Object
-
.my_gets ⇒ Object
Input======================.
- .nil_error ⇒ Object
- .paginate(identifier) ⇒ Object
-
.prompt ⇒ Object
——————-input———————-.
-
.randQ ⇒ Object
Quotes=====================.
-
.rdo_prefix ⇒ Object
——————strings———————.
- .redH(str) ⇒ Object
- .search_error ⇒ Object
- .search_list(matches) ⇒ Object
- .sepB ⇒ Object
-
.sepL ⇒ Object
—————–separators——————-.
- .sepR ⇒ Object
-
.signature ⇒ Object
Signature====================.
- .view_full ⇒ Object
-
.wrapped(s, width = 60) ⇒ Object
currently not being used.
Instance Attribute Details
#counter ⇒ Object (readonly)
Properties===================
3 4 5 |
# File 'lib/ruby_doc/cli/ui.rb', line 3 def counter @counter end |
Class Method Details
.browse_control(identifier, page) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ruby_doc/cli/ui.rb', line 103 def self.browse_control(identifier, page) prompt input = my_gets case input when "n" paginate(identifier) when "m" RubyDoc::CLI.start when "exit!" exit! end if !input.to_i.between?(1,page.count) browse_error(input, identifier, page) else Processor.load_doc(page[input.to_i-1]) end end |
.browse_error(input, identifier, page) ⇒ Object
392 393 394 395 396 397 398 399 400 |
# File 'lib/ruby_doc/cli/ui.rb', line 392 def self.browse_error(input, identifier, page) if identifier == "Last" list_error(page) browse_control(identifier, page) else browse_list_error(page) browse_control(identifier, page) end end |
.browse_list(page, identifier) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/ruby_doc/cli/ui.rb', line 246 def self.browse_list(page, identifier) puts sepL page.each_with_index do |doc, index| if doc.type == "Class" || doc.type == "Module" li = ["#{index + 1}.".yellow, doc.name.light_cyan] else li = ["#{index + 1}.".yellow, doc.name.cyan] end puts li.join(" ") end if identifier == "Last" puts sepR puts "End of List".red end puts sepR (page) if identifier == "Last" (page) if !(identifier == "Last") browse_control(identifier, page) end |
.browse_list_error(page) ⇒ Object
402 403 404 |
# File 'lib/ruby_doc/cli/ui.rb', line 402 def self.browse_list_error(page) print redH("\n Enter # to view, 'n' for next page 'm' for main or 'exit!' to leave ") end |
.browse_menu(page) ⇒ Object
332 333 334 335 336 337 338 |
# File 'lib/ruby_doc/cli/ui.rb', line 332 def self.(page) puts "View Doc ".light_cyan + "(".cyan + "#".yellow + ")".cyan puts "Next Page ".light_cyan + "(".cyan + "n".yellow + ")".cyan puts "Return To ".cyan + "Main Menu ".light_cyan + "(".cyan + "m".yellow + ")".cyan puts "Leave".light_cyan + " (".cyan + "exit!".yellow + ")".cyan print randQ end |
.clear ⇒ Object
9 10 11 |
# File 'lib/ruby_doc/cli/ui.rb', line 9 def self.clear system "clear" or system "cls" end |
.cyanH(str) ⇒ Object
red highlight
460 461 462 |
# File 'lib/ruby_doc/cli/ui.rb', line 460 def self.cyanH(str) str.colorize(color: :white, background: :cyan) end |
.display_class(doc, view = "short") ⇒ Object
——————-docs———————–
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/ruby_doc/cli/ui.rb', line 137 def self.display_class(doc, view="short") puts sepL # header # puts "TITLE: ".cyan + doc.name.upcase puts "TYPE: ".cyan + doc.type.upcase puts "\nDESCRIPTION:".cyan # documentation # if view == "short" puts wrapped(doc.short) puts view_full elsif view == "full" puts doc.documentation end # footer # puts "Methods: ".cyan + "#{doc.methods.count}".yellow puts "Source: #{doc.url}".red puts sepR # control # (doc) display_class_control(doc) end |
.display_class_control(doc) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ruby_doc/cli/ui.rb', line 51 def self.display_class_control(doc) prompt input = my_gets case input when "full" display_class(doc, "full") when "1" method_list(doc) when "s" Processor.save(doc) when "m" RubyDoc::CLI.start when "exit!" exit! else display_class_error(doc) end end |
.display_class_error(doc) ⇒ Object
382 383 384 385 |
# File 'lib/ruby_doc/cli/ui.rb', line 382 def self.display_class_error(doc) print redH("\n Please enter '1' to view methods, 'm' for main, or 'exit!' to leave ") display_class_control(doc) end |
.display_class_menu(doc) ⇒ Object
317 318 319 320 321 322 323 |
# File 'lib/ruby_doc/cli/ui.rb', line 317 def self.(doc) puts "Save To ".cyan + "Favorites ".light_cyan + "(".cyan + "s".yellow + ")".cyan puts "View ".cyan + "Methods ".light_cyan + "For #{doc.name} (".cyan + "1".yellow + ")".cyan puts "Return To ".cyan + "Main Menu ".light_cyan + "(".cyan + "m".yellow + ")".cyan puts "Leave".light_cyan + " (".cyan + "exit!".yellow + ")".cyan print randQ end |
.display_method(doc) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/ruby_doc/cli/ui.rb', line 163 def self.display_method(doc) puts sepL puts "Title: ".cyan + doc.name.upcase puts "Type: ".cyan + doc.type.upcase puts "\nDescription:".cyan puts doc.documentation puts "Source: #{doc.url}".red puts sepR #-----------future fix------------# # description = doc.doc # puts uie.wrapped(description, 55) #-----------future fix------------# display_method_control(doc) end |
.display_method_control(doc) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ruby_doc/cli/ui.rb', line 71 def self.display_method_control(doc) prompt input = my_gets case input when "s" Processor.save(doc) when "m" RubyDoc::CLI.start when "exit!" exit! else display_method_error end end |
.display_method_error ⇒ Object
387 388 389 390 |
# File 'lib/ruby_doc/cli/ui.rb', line 387 def self.display_method_error print redH("\n Please enter 'm' for main menu or 'exit!' to leave ") display_method_control end |
.display_method_menu ⇒ Object
325 326 327 328 329 330 |
# File 'lib/ruby_doc/cli/ui.rb', line 325 def self. puts "Save To ".cyan + "Favorites ".light_cyan + "(".cyan + "s".yellow + ")".cyan puts "Return To ".cyan + "Main Menu ".light_cyan + "(".cyan + "m".yellow + ")".cyan puts "Leave".light_cyan + " (".cyan + "exit!".yellow + ")".cyan print randQ end |
.favorites_error ⇒ Object
353 354 355 356 357 |
# File 'lib/ruby_doc/cli/ui.rb', line 353 def self.favorites_error sleep(0.1) print redH("\n You have no favorites saved ") main_control end |
.favorites_list ⇒ Object
——————-lists———————-
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/ruby_doc/cli/ui.rb', line 181 def self.favorites_list # Normalize Favorites List list = [] File.open("usr/favorites.txt").each do |li| list << li.chomp end # if favorites is empty error & back to main control if list.empty? favorites_error main_control else puts sepL puts puts sepB # Iterated and display normalized favorites list list.each_with_index do |f, index| li = ["#{index + 1}.".yellow, f.cyan] puts li.join(" ") end puts sepR (list) favorites_list_control(list) end end |
.favorites_list_control(list) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby_doc/cli/ui.rb', line 35 def self.favorites_list_control(list) prompt input = my_gets if input == "m" RubyDoc::CLI.start elsif input == "exit!" exit! elsif !input.to_i.between?(1,list.count) list_error(list) else Processor.find_fav(list[input.to_i-1]) end favorites_list_control(list) end |
.favorites_message ⇒ Object
——————messages——————–
452 453 454 |
# File 'lib/ruby_doc/cli/ui.rb', line 452 def self. "Please Note: ".black + "/usr".light_black + " dir must exist in your current dir for\nthis to work. To learn more go to main menu & enter (".black + "?" + ")".black end |
.last_page_menu(page) ⇒ Object
340 341 342 343 344 345 |
# File 'lib/ruby_doc/cli/ui.rb', line 340 def self.(page) puts "View Doc ".light_cyan + "(".cyan + "#".yellow + ")".cyan puts "Return To ".cyan + "Main Menu ".light_cyan + "(".cyan + "m".yellow + ")".cyan puts "Leave".light_cyan + " (".cyan + "exit!".yellow + ")".cyan print randQ end |
.learn_more ⇒ Object
—————–learn more——————-
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/ruby_doc/cli/ui.rb', line 271 def self.learn_more puts sepB puts "FAVORITES".cyan puts sepB puts wrapped("In this early version of the favorites feature there are a few things to note, for this to work properly.", 55) puts "\n" puts wrapped("When you install ruby_doc we create a dir (usr) with a file inside (favorites.txt) in your current directory. In order for favorites to read from this file and output your saved entries this dir/file must remain in your current dir.", 55) puts "\n" puts wrapped("If at any point you switch directories and want to have access to your favorites simply copy or move the (usr) dir to the root/top level of the directory you'd like to have access to your ruby_doc favorites in.", 55) puts "\n" puts "Please do not modify this file!".red puts wrapped("If you do accidentally, and encounter any problems displaying, do the following. Open the favorites.txt file in your usr dir and make sure each entry is on a new/separate line. If you still have issues you will have to delete your usr folder. When you run ruby_doc again it will check for the usr dir, if it doesn't exist, it will create a new one for you. Would be a good idea to save your entries before deleting usr for reference.", 55) puts "\n" puts wrapped("This is something that obviously will be improved to persist through all your directories in the future, but give me time. Thanks for using RUBY DOC!", 55) puts sepB puts "COMING SOON".cyan puts sepB puts "\n" + Scraper.coming_soon + "\n" puts sepB puts "CHANGELOG".cyan puts sepB puts "\n" + Scraper.changelog ("learn") main_control end |
.list_control(matches) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ruby_doc/cli/ui.rb', line 87 def self.list_control(matches) prompt input = my_gets if input == "m" RubyDoc::CLI.start elsif input == "exit!" exit! elsif !input.to_i.between?(1,matches.count) list_error(matches) else Processor.load_doc(matches[input.to_i-1]) end list_control(matches) end |
.list_error(matches) ⇒ Object
374 375 376 |
# File 'lib/ruby_doc/cli/ui.rb', line 374 def self.list_error(matches) print redH("\n Enter selection number, 'm' for main or 'exit!' to leave ") end |
.list_menu(matches) ⇒ Object
310 311 312 313 314 315 |
# File 'lib/ruby_doc/cli/ui.rb', line 310 def self.(matches) puts "View Doc ".light_cyan + "(".cyan + "#".yellow + ")".cyan puts "Return To ".cyan + "Main Menu ".light_cyan + "(".cyan + "m".yellow + ")".cyan puts "Leave".light_cyan + " (".cyan + "exit!".yellow + ")".cyan print randQ end |
.loading_animation ⇒ Object
Goes inside iterator - last line
423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/ruby_doc/cli/ui.rb', line 423 def self.loading_animation loading = "" print loading << ". ".cyan if @counter == 50 || @counter == 100 || @counter == 150 || @counter == 200 || @counter == 250 || @counter == 300 || @counter == 350 || @counter == 400 || @counter == 450 || @counter == 500 || @counter == 550 || @counter == 600 || @counter == 650 || @counter == 700 || @counter == 750 || @counter == 800 || @counter == 850 || @counter == 900 || @counter == 950 || @counter == 1000 || @counter == 1150 || @counter == 1200 || @counter == 1250 || @counter == 1300 || @counter == 1350 || @counter == 1400 || @counter == 1450 || @counter == 1500 end |
.loading_message ⇒ Object
Goes above iterator
419 420 421 |
# File 'lib/ruby_doc/cli/ui.rb', line 419 def self. puts cyanH(" Loading Database ") + " ☠️" end |
.main_control ⇒ Object
Control=====================
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_doc/cli/ui.rb', line 13 def self.main_control prompt input = my_gets if input.split.size > 1 main_error elsif input == "b" paginate("start") elsif input == "*" favorites_list elsif input == "exit!" exit! elsif input == "?" learn_more else matches = Processor.search(input) search_error if matches.empty? search_list(matches) if matches end end |
.main_error ⇒ Object
Error======================
347 348 349 350 351 |
# File 'lib/ruby_doc/cli/ui.rb', line 347 def self.main_error sleep(0.1) print redH("\n Input Must Be 1 Word, 'b' to browse, or 'exit!' to leave ") main_control end |
.main_menu(from = "default") ⇒ Object
Menus======================
300 301 302 303 304 305 306 307 308 |
# File 'lib/ruby_doc/cli/ui.rb', line 300 def self.(from="default") puts sepR puts "To search... enter a single (".cyan + "word".yellow + ") associated with Ruby. \nI will try to find a match in my database for you.".cyan puts sepB puts "To Browse enter (".cyan + "b".yellow + ")".cyan + " ||| ".black + "To view your favorites enter (".cyan + "*".yellow + ")".cyan puts sepR puts "Enter '?' to Learn More about Alpha Ruby-Doc\n".black unless from == "learn" print cyanH("\n Happy Hunting! ") end |
.method_list(doc) ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/ruby_doc/cli/ui.rb', line 230 def self.method_list(doc) puts sepR doc.methods.each_with_index do |method, index| if !method.nil? li = ["#{index + 1}.".yellow, method.name.cyan] puts li.join(" ") end end puts sepR (doc.methods) list_control(doc.methods) end |
.my_gets ⇒ Object
Input======================
5 6 7 |
# File 'lib/ruby_doc/cli/ui.rb', line 5 def self.my_gets gets.strip.to_s.downcase end |
.nil_error ⇒ Object
378 379 380 |
# File 'lib/ruby_doc/cli/ui.rb', line 378 def self.nil_error print redH("\n Enter selection number, 'm' for main or 'exit!' to leave ") end |
.paginate(identifier) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ruby_doc/cli/ui.rb', line 123 def self.paginate(identifier) case identifier when "start" Processor.page1 when "Page1" Processor.page2 when "Page2" Processor.page3 when "Page3" Processor.last end end |
.prompt ⇒ Object
——————-input———————-
436 437 438 |
# File 'lib/ruby_doc/cli/ui.rb', line 436 def self.prompt print " >> ".cyan end |
.randQ ⇒ Object
Quotes=====================
408 409 410 411 412 413 414 415 416 |
# File 'lib/ruby_doc/cli/ui.rb', line 408 def self.randQ puts sepB html = Nokogiri::HTML(open("https://fortrabbit.github.io/quotes/")) container = html.search(".row.gutter-l.wrap") quotes = container.search("p").map {|quote| quote.text.gsub(/[\n]\s+/, "")} quote = " "+ quotes[rand(0..180)]+ " " wrapped(quote, 55).black end |
.rdo_prefix ⇒ Object
——————strings———————
464 465 466 |
# File 'lib/ruby_doc/cli/ui.rb', line 464 def self.rdo_prefix "https://ruby-doc.org/core-2.4.3/" end |
.redH(str) ⇒ Object
456 457 458 |
# File 'lib/ruby_doc/cli/ui.rb', line 456 def self.redH(str) str.colorize(color: :white, background: :red) end |
.search_error ⇒ Object
359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/ruby_doc/cli/ui.rb', line 359 def self.search_error puts sepB puts "NO CIGAR!".red puts "I couldn't find what you're looking for.".black puts "How about trying a Ruby ".black + "Method" + ", ".black + "Class" + " or ".black + "Module" + " name.".black puts sepB puts "NOT SURE?".red puts "You can always browse with ".black + "'b'" + " & learn something new.".black + ":)" puts sepB print redH("\n Try a new word, enter 'b' to browse, or 'exit!' to leave ") main_control end |
.search_list(matches) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/ruby_doc/cli/ui.rb', line 210 def self.search_list(matches) puts sepL matches.each_with_index do |doc, index| if doc.type == "Class" || doc.type == "Module" li = ["#{index + 1}.".yellow, doc.name.light_cyan] else li = ["#{index + 1}.".yellow, doc.name.cyan] end puts li.join(" ") end puts sepR puts "Classes and Modules are".cyan + " Highlighted".light_cyan puts sepR (matches) list_control(matches) end |
.sepB ⇒ Object
448 449 450 |
# File 'lib/ruby_doc/cli/ui.rb', line 448 def self.sepB "=".black*56 end |
.sepL ⇒ Object
—————–separators——————-
440 441 442 |
# File 'lib/ruby_doc/cli/ui.rb', line 440 def self.sepL "=".cyan*28 + "=".white*28 end |
.sepR ⇒ Object
444 445 446 |
# File 'lib/ruby_doc/cli/ui.rb', line 444 def self.sepR "=".white*28 + "=".cyan*28 end |
.signature ⇒ Object
Signature====================
493 494 495 496 497 498 |
# File 'lib/ruby_doc/cli/ui.rb', line 493 def self.signature puts "\n"+"=".white*28 + "=".cyan*28 puts %q( ALPHA™ ╦═╗╦ ╦╔╗ ╦ ╦ ╔╦╗╔═╗╔═╗╔═╗ ╠╦╝║ ║╠╩╗╚╦╝ ║║║ ║║ ╚═╗ ╩╚═╚═╝╚═╝ ╩ ═╩╝╚═╝╚═╝╚═╝).cyan end |
.view_full ⇒ Object
468 469 470 471 472 |
# File 'lib/ruby_doc/cli/ui.rb', line 468 def self.view_full puts sepB puts "To View Full Documentation Enter".cyan + " full".yellow puts sepB end |
.wrapped(s, width = 60) ⇒ Object
currently not being used
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/ruby_doc/cli/ui.rb', line 475 def self.wrapped(s, width=60) lines = [] line = "" s.split(/\s+/).each do |word| if line.size + word.size >= width lines << line line = word elsif line.empty? line = word else line << " " << word end end lines << line if line return lines.join "\n" end |