Class: SharksAhead::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/sharks_ahead/cli.rb

Instance Method Summary collapse

Instance Method Details

#answer_dead_or_aliveObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/sharks_ahead/cli.rb', line 62

def answer_dead_or_alive
  answer = nil
  while answer != "exit"
    answer = gets.chomp
    case answer
    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

#answer_lookObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sharks_ahead/cli.rb', line 31

def answer_look
  answer = nil
  while answer != "exit"
    answer = gets.chomp
    case answer
    when /^(y|yes)$/i then answer_yes
    when /^(n|no)$/i  then goodbye1
    else belay_that
    end
  end
end

#answer_yesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sharks_ahead/cli.rb', line 43

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
end

#belay_thatObject



156
157
158
# File 'lib/sharks_ahead/cli.rb', line 156

def belay_that
  print "\nBelay that! Ye must make a proper choice.  "
end

#callObject



3
4
5
# File 'lib/sharks_ahead/cli.rb', line 3

def call
  welcome
end

#description_extinctObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/sharks_ahead/cli.rb', line 85

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 word_wrap("\n#{the_shark[:description]}\n\n", 75)
    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_livingObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/sharks_ahead/cli.rb', line 113

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 word_wrap("\n#{the_shark[:description]}\n\n", 75)
    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_choicesObject



131
132
133
134
135
# File 'lib/sharks_ahead/cli.rb', line 131

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

#goodbye1Object



142
143
144
145
146
147
148
# File 'lib/sharks_ahead/cli.rb', line 142

def goodbye1
  puts "\nWell then, ye must be a wee babe. I'll sing ye a lullaby instead.\n\n"
  lullaby
  puts "\nCome back to see me when ye get yer mettle up."
  ship_end
  exit
end

#goodbye2Object



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_extinctObject



75
76
77
78
79
80
81
82
83
# File 'lib/sharks_ahead/cli.rb', line 75

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_livingObject



103
104
105
106
107
108
109
110
111
# File 'lib/sharks_ahead/cli.rb', line 103

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

#lullabyObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/sharks_ahead/cli.rb', line 160

def lullaby
  # Seal Lullaby from The Jungle Book by Rudyard Kipling
  # http://www.poetryloverspage.com/poets/kipling/seal_lullaby.html
  puts "  Oh! hush thee, my baby, the night is behind us,\n    And black are the waters that sparkled so green.\n  The moon, o'er the combers, looks downward to find us\n    At rest in the hollows that rustle between.\n  Where billow meets billow, there soft be thy pillow;\n    Ah, weary wee flipperling, curl at thy ease!\n  The storm shall not wake thee, nor shark overtake thee,\n    Asleep in the arms of the slow-swinging seas.\n  DOC\nend\n"

#ship_endObject



175
176
177
178
179
180
181
182
# File 'lib/sharks_ahead/cli.rb', line 175

def ship_end
  puts "     .                                             _~        *"
  puts "                       .             *          _~ )_)_~"
  puts "               *                                )_))_))_)"
  puts "    *       .               *       .           _!__!__!_         ."
  puts "                                                \\______t/"
  puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"
end

#welcomeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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 "                  \u2554\u2550\u2550\u2550\u2557 \u2554\u2557 \u2554\u2557 \u2554\u2550\u2550\u2550\u2557 \u2554\u2550\u2550\u2550\u2557 \u2554\u2557\u2554\u2550\u2557 \u2554\u2557\n                  \u2551\u2554\u2550\u2557\u2551 \u2551\u2551 \u2551\u2551 \u2551\u2554\u2550\u2557\u2551 \u2551\u2554\u2550\u2557\u2551 \u2551\u2551\u2551\u2554\u255D \u2551\u2551\n                  \u2551\u255A\u2550\u2550\u2557 \u2551\u255A\u2550\u255D\u2551 \u2551\u2551 \u2551\u2551 \u2551\u255A\u2550\u255D\u2551 \u2551\u255A\u255D\u255D  \u2551\u2551\n                  \u255A\u2550\u2550\u2557\u2551 \u2551\u2554\u2550\u2557\u2551 \u2551\u255A\u2550\u255D\u2551 \u2551\u2554\u2557\u2554\u255D \u2551\u2554\u2557\u2551  \u255A\u255D\n                  \u2551\u255A\u2550\u255D\u2551 \u2551\u2551 \u2551\u2551 \u2551\u2554\u2550\u2557\u2551 \u2551\u2551\u2551\u255A\u2557 \u2551\u2551\u2551\u255A\u2557 \u2554\u2557\n                  \u255A\u2550\u2550\u2550\u255D \u255A\u255D \u255A\u255D \u255A\u255D \u255A\u255D \u255A\u255D\u255A\u2550\u255D \u255A\u255D\u255A\u2550\u255D \u255A\u255D\n  DOC\n\n  # ascii ship art from http://chris.com/ascii/index.php?art=transportation/nautical\n  puts \"               _~\"\n  puts \"            _~ )_)_~ \"\n  puts \"            )_))_))_)    Thar be sharks ahead! \"\n  puts \"            _!__!__!_\"\n  puts \"       ~  ~ \\\\______t/\"\n  puts \"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\\\\~~~~~~~|\\\\~~~~~~~~~~~~~~~~\"\n  print \"\\nAre ye prepared to look fer 'em? Tell me! Yes or no?  \"\n\n  answer_look\nend\n"

#word_wrap(text, width = 70) ⇒ Object

Word wrap from Ruby Cookbook



138
139
140
# File 'lib/sharks_ahead/cli.rb', line 138

def word_wrap(text, width = 70)
  text.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n")
end