Class: MartialArts::CLI

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

Overview

CLI Controler

Instance Method Summary collapse

Instance Method Details

#all_styles_submenuObject



173
174
175
176
177
178
179
180
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
# File 'lib/martial_arts/cli.rb', line 173

def all_styles_submenu
  size = MartialArts::Styles.all.size
  input = nil

  messages("all styles")
  MartialArts::Styles.styles_list.each.with_index(1) {|style_instance, i| puts "#{i}. #{style_instance.name}" }
  messages("user")

  while input != "back"
    input = gets.strip.downcase

    case input
    when /\d\d*/ #Checks if input is a number

      if (1...size+1).include?(input.to_i)
        style = MartialArts::Styles.styles_list[input.to_i-1]

        display_info_for(style)
        messages("list or back")
      else
        messages("invalid")
      end

    when "list"
      messages("all styles")
      MartialArts::Styles.styles_list.each.with_index(1) {|style_instance, i| puts "#{i}. #{style_instance.name}" }
      messages("user")
    when "back"
      break
    else
      messages("invalid")
    end

  end
end

#callObject



4
5
6
7
8
# File 'lib/martial_arts/cli.rb', line 4

def call
  messages("greeting")

  menu
end

#country_styles_sub_submenuObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/martial_arts/cli.rb', line 130

def country_styles_sub_submenu
  size = @style_list.size
  input = nil

  while input != "back"
    input = gets.strip.downcase

    case input
    when /\d\d*/  #checks if input is a number

      if (1...size+1).include?(input.to_i)

        display_info_for(@style_list[input.to_i-1])
        messages("list or back")
      else
        messages("invalid")
      end

    when "list"
      styles_by_country_list(@country_input)
    when "back"
      messages("countries")
      MartialArts::Countries.country_list.each.with_index(1) {|country, i| puts "#{i}. #{country}"}
      messages("user")
      break
    else
      messages("invalid")
    end

  end
end

#display_info_for(style) ⇒ Object



342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/martial_arts/cli.rb', line 342

def display_info_for(style)

  puts " "
  puts "                              #{"Style info for".magenta} #{style.name.cyan}"
  puts " "
  puts "Country: #{style.country_name.green}"
  puts "Fighting Focus: #{style.fighting_focus_name.yellow}"
  puts " "
  puts "Description: #{style.description.red}"
  puts " "
  puts "More Info: #{style.website.magenta}"
  puts " "

end

#fighting_focus_submenuObject



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/martial_arts/cli.rb', line 209

def fighting_focus_submenu
  @focus_list = {1 => "Striking", 2 => "Grappling", 3 => "Weaponry", 4 => "Hybrid", 5 => "Internal"}
  input = nil

  messages("fighting focus menu")
  @focus_list.each {|i, focus| puts "#{i}. #{focus}" }
  messages("user")

  while input != "back"
    input = gets.strip.downcase

    case input
    when "1", "2", "3", "4", "5"
      styles_by_focus_list(input)
      styles_by_focus_sub_submenu

    when "list"
      messages("fighting focus menu")
      @focus_list.each {|i, focus| puts "#{i}. #{focus}" }
      messages("user")
    when "back"
      break
    else
      messages("invalid")
    end

  end
end

#martial_arts_by_country_submenuObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/martial_arts/cli.rb', line 95

def martial_arts_by_country_submenu
  size = MartialArts::Countries.country_list.size
  input = nil

  messages("countries")
  MartialArts::Countries.country_list.each.with_index(1) {|country, i| puts "#{i}. #{country}"}
  messages("user")

  while input != "back"
    input = gets.strip.downcase

    case input
    when /\d\d*/  #checks if input is a number

      if (1...size+1).include?(input.to_i)
        styles_by_country_list(input)

        country_styles_sub_submenu
      else
        messages("invalid")
      end

    when "list"
      messages("countries")
      MartialArts::Countries.country_list.each.with_index(1) {|country, i| puts "#{i}. #{country}"}
      messages("user")
    when "back"
      break
    else
      messages("invalid")
    end

  end
end


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
# File 'lib/martial_arts/cli.rb', line 10

def menu
  navigation = {
    1 => [ "Popular Martial Arts", method(:popular_martial_arts_submenu) ],
    2 => [ "Martial Arts by Country", method(:martial_arts_by_country_submenu) ],
    3 => [ "Martial Art Styles", method(:all_styles_submenu) ],
    4 => [ "Martial Art by Fighting-Focus", method(:fighting_focus_submenu) ]
  }

  input = nil

  while input != "exit"
    puts " "
    navigation.each {|i, submenu_array| puts "#{i}. #{submenu_array[0]}" }
    puts " "
    puts "Please enter the corresponding number or type exit".cyan

    input = gets.strip.downcase

    case input
    when "1", "2", "3", "4"
      navigation[input.to_i][1].()

    when "missing data"                                                 #hidden submenu
      MartialArts::Styles.missing_info.each.with_index(1) do |style_instance, i|
        puts "#{i}. #{style_instance.name}"
        puts "Country: #{style_instance.country_name}" if style_instance.country_name == "N/A"
        puts "Fighting-Focus: #{style_instance.fighting_focus_name}" if style_instance.fighting_focus_name == "N/A"
        puts "Description: #{style_instance.description}" if style_instance.description == "N/A"
        puts " "
      end
    when "exit"
      #exits the application
    else
      messages("invalid")
    end

  end
end

#messages(type) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/martial_arts/cli.rb', line 279

def messages(type)
  case type
  when "greeting"

    puts "OOOOOOSSSsss".magenta
    puts "Choose your destiny".blue
    #maybe want to add delay from first puts to second, maybe 3 seconds.
  when "invalid"

    puts ""
    puts "I'm confused can you try that again?".cyan
    puts ""

  when "user"

    puts ""
    puts "Enter the corresponding number for more information".light_cyan
    puts "#{"Otherwise type".cyan} list #{"or".cyan} back"

  when "styles by focus"

    puts ""
    puts "                              #{"FIGHTING FOCUS:".magenta} #{@focus_list[@focus_input.to_i]}"
    puts ""

  when "fighting focus menu"

    puts ""
    puts "                              CHOOSE YOUR FIGHTING FOCUS".magenta
    puts ""

  when "all styles"

    puts ""
    puts "                              #{"ALL STYLES".magenta}"
    puts ""

  when "styles by country"

    puts ""
    puts "                              #{"MARTIAL ARTS FROM".magenta} #{@country.upcase.cyan}"
    puts ""

  when "countries"

    puts ""
    puts "                              #{"COUNTRIES".magenta}"
    puts ""

  when "popular"

    puts ""
    puts "                              POPULAR MARTIAL ARTS".magenta#15 tabs for title
    puts ""

  when "list or back"

    puts "#{"Type".cyan} list #{"or".cyan} back"

  else
  end
end


84
85
86
87
88
89
90
91
92
93
# File 'lib/martial_arts/cli.rb', line 84

def popular_list

  messages("popular")
  MartialArts::Styles.popular.each.with_index(1) do |style_instance, i|
    puts "#{i}. #{style_instance.name}" if style_instance.class == MartialArts::Styles
    puts "#{i}. #{style_instance}" if style_instance.class == String  #This could be removed if it is performed along with the scrape
  end
  messages("user")

end


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
# File 'lib/martial_arts/cli.rb', line 49

def popular_martial_arts_submenu
  #this outputs the 10 most popular martial arts in the world.
  input = nil

  popular_list

  while input != "back"
    input = gets.strip.downcase

    case input
    when "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
      style = MartialArts::Styles.popular[input.to_i - 1]

      if style == "Chinese Martial Arts"
        MartialArts::Styles.search_by_country("China").each do |style_instance|
          puts "#{display_info_for(style_instance)}"
        end

        messages("list or back")
      else
        display_info_for(style)
        messages("list or back")
      end

    when "list"
      popular_list
    when "back"
      break
    else
      messages("invalid")
    end

  end
end

#styles_by_country_list(input) ⇒ Object



162
163
164
165
166
167
168
169
170
171
# File 'lib/martial_arts/cli.rb', line 162

def styles_by_country_list(input)
  @country_input = input
  @country = MartialArts::Countries.country_list[input.to_i-1]
  @style_list = MartialArts::Styles.search_by_country(@country)

  messages("styles by country")
  @style_list.each.with_index(1) {|style_instance, i| puts "#{i}. #{style_instance.name}"}
  messages("user")

end

#styles_by_focus_list(input) ⇒ Object



269
270
271
272
273
274
275
276
277
# File 'lib/martial_arts/cli.rb', line 269

def styles_by_focus_list(input)
  @focus_input = input  #save input from focus_submenu so user can return
  @focus_style_list = MartialArts::Styles.search_by_focus(@focus_list[input.to_i])

  messages("styles by focus")
  @focus_style_list.each.with_index(1) {|style_instance, i| puts "#{i}. #{style_instance.name}" }
  messages("user")

end

#styles_by_focus_sub_submenuObject



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/martial_arts/cli.rb', line 238

def styles_by_focus_sub_submenu
  size = @focus_style_list.size
  input = nil

  while input != "back"
    input = gets.strip.downcase

    case input
    when /\d\d*/  #checks if input is a number

      if (1...size+1).include?(input.to_i)
        display_info_for(@focus_style_list[input.to_i-1])
        messages("list or back")
      else
        messages("invalid")
      end

    when "list"
      styles_by_focus_list(@focus_input)
    when "back"
      messages("fighting focus menu")
      @focus_list.each {|i, focus| puts "#{i}. #{focus}" }
      messages("user")
      break
    else
      messages("invalid")
    end

  end
end