Class: SharksAhead::CLI
- Inherits:
-
Object
- Object
- SharksAhead::CLI
- Defined in:
- lib/sharks_ahead/cli.rb
Instance Method Summary collapse
- #answer_yes ⇒ Object
- #belay_that ⇒ Object
- #call ⇒ Object
- #description_extinct ⇒ Object
- #description_living ⇒ Object
- #give_choices ⇒ Object
- #goodbye1 ⇒ Object
- #goodbye2 ⇒ Object
- #list_extinct ⇒ Object
- #list_living ⇒ Object
- #ship_end ⇒ Object
- #welcome ⇒ Object
Instance Method Details
#answer_yes ⇒ Object
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 |
# File 'lib/sharks_ahead/cli.rb', line 39 def answer_yes puts "\e[H\e[2J" # ascii shark art from http://www.ascii-art.de/ascii/s/sharks.txt puts " , " puts " .'; " puts " .-'` .' " puts " ,`.-'-.`\ " puts " ; / '-'" puts " | \ ,-," puts " \ '-.__ )_`'._ " puts " '. ``` ``'--._ " puts " .-' , `'-. Are ye lookin' fer dead sharks" puts " '-'`-._ (( o ) or livin'? Tell me!" puts " `'--....(`- ,__..--' " print " '-'` Dead or alive? " answer_dead_or_alive = nil while answer_dead_or_alive != "exit" answer_dead_or_alive = gets.chomp case answer_dead_or_alive when /^(d|dead)$/i then list_extinct when /^(a|alive)$/i then list_living when /^(e|exit)$/i then goodbye2 else belay_that end end end |
#belay_that ⇒ Object
156 157 158 |
# File 'lib/sharks_ahead/cli.rb', line 156 def belay_that print "\nBelay that! Ye must make a proper choice. " end |
#call ⇒ Object
3 4 5 |
# File 'lib/sharks_ahead/cli.rb', line 3 def call welcome end |
#description_extinct ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sharks_ahead/cli.rb', line 77 def description_extinct extinct_input = nil while extinct_input != "exit" give_choices extinct_input = gets.chomp the_shark = @shark_extinct[extinct_input.to_i-1] case extinct_input when /([1-7])/ then puts "\n#{the_shark[:description]}\n\n" when /^(l|list)$/i then list_extinct when /^(e|exit)$/i then goodbye2 when /^(s|start)$/i then welcome else belay_that end end end |
#description_living ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/sharks_ahead/cli.rb', line 105 def description_living living_input = nil while living_input != "exit" give_choices living_input = gets.chomp the_shark = @shark_living[living_input.to_i-1] case living_input when /([1-7])/ then puts "\n#{the_shark[:description]}\n\n" when /^(l|list)$/i then list_living when /^(e|exit)$/i then goodbye2 when /^(s|start)$/i then welcome else belay_that end end end |
#give_choices ⇒ Object
123 124 125 126 127 |
# File 'lib/sharks_ahead/cli.rb', line 123 def give_choices puts "\nWhat's yer lucky number? Else ye may abandon ship by typin' exit." puts "If ye cannot recall the list, type list." print "If ye wish to start again, ye may type start. " end |
#goodbye1 ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/sharks_ahead/cli.rb', line 129 def goodbye1 puts "\nWell then, ye must be a wee babe. I'll sing ye a lullaby instead.\n\n" # Seal Lullaby from The Jungle Book by Rudyard Kipling # http://www.poetryloverspage.com/poets/kipling/seal_lullaby.html puts <<-DOC Oh! hush thee, my baby, the night is behind us, And black are the waters that sparkled so green. The moon, o'er the combers, looks downward to find us At rest in the hollows that rustle between. Where billow meets billow, there soft be thy pillow; Ah, weary wee flipperling, curl at thy ease! The storm shall not wake thee, nor shark overtake thee, Asleep in the arms of the slow-swinging seas. DOC puts "\nCome back to see me when ye get yer mettle up." ship_end exit end |
#goodbye2 ⇒ Object
150 151 152 153 154 |
# File 'lib/sharks_ahead/cli.rb', line 150 def goodbye2 puts "\nFare thee well me matey. Ye may join me crew again anytime!\n\n" ship_end exit end |
#list_extinct ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/sharks_ahead/cli.rb', line 67 def list_extinct puts "\nWe'll be lookin' fer extinct ones. Here y'arr:\n\n" @shark_extinct = SharksAhead::SharkExtinct.get_extinct_sharks @shark_extinct.each.with_index(1) do |shark, i| printf "%3s - %-50s\n", i, shark[:name] end description_extinct end |
#list_living ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/sharks_ahead/cli.rb', line 95 def list_living puts "\nLet's find thee a livin' one!\n\n" @shark_living = SharksAhead::SharkLiving.get_living_sharks @shark_living.each.with_index(1) do |shark, i| printf "%3s - %-50s\n", i, shark[:name] end description_living end |
#ship_end ⇒ Object
160 161 162 163 164 165 166 167 |
# File 'lib/sharks_ahead/cli.rb', line 160 def ship_end puts " . _~ *" puts " . * _~ )_)_~" puts " * )_))_))_)" puts " * . * . _!__!__!_ ." puts " \\______t/" puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n" end |
#welcome ⇒ Object
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 |
# File 'lib/sharks_ahead/cli.rb', line 7 def welcome puts "\e[H\e[2J" # text art generator at http://fsymbols.com/generators/carty/ puts <<-DOC ╔═══╗ ╔╗ ╔╗ ╔═══╗ ╔═══╗ ╔╗╔═╗ ╔╗ ║╔═╗║ ║║ ║║ ║╔═╗║ ║╔═╗║ ║║║╔╝ ║║ ║╚══╗ ║╚═╝║ ║║ ║║ ║╚═╝║ ║╚╝╝ ║║ ╚══╗║ ║╔═╗║ ║╚═╝║ ║╔╗╔╝ ║╔╗║ ╚╝ ║╚═╝║ ║║ ║║ ║╔═╗║ ║║║╚╗ ║║║╚╗ ╔╗ ╚═══╝ ╚╝ ╚╝ ╚╝ ╚╝ ╚╝╚═╝ ╚╝╚═╝ ╚╝ DOC # ascii ship art from http://chris.com/ascii/index.php?art=transportation/nautical puts " _~" puts " _~ )_)_~ " puts " )_))_))_) Thar be sharks ahead! " puts " _!__!__!_" puts " ~ ~ \\______t/" puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\\~~~~~~~|\\~~~~~~~~~~~~~~~~" print "\nAre ye prepared to look fer 'em? Tell me! Yes or no? " answer_look = nil while answer_look != "exit" answer_look = gets.chomp case answer_look when /^(y|yes)$/i then answer_yes when /^(n|no)$/i then goodbye1 else belay_that end end end |