Class: List

Inherits:
Object
  • Object
show all
Defined in:
lib/classes/List.rb

Class Method Summary collapse

Class Method Details

.list_all(data) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/classes/List.rb', line 60

def self.list_all(data)
  data.each do |hash|
    Print.print_pokemon_condensed(hash)
  end
  puts '-' * 40
  Main_menu.return?
end

.list_by(data, attribute, value) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/classes/List.rb', line 68

def self.list_by(data, attribute, value)
  data.each do |hash|
    Print.print_pokemon_condensed(hash) if hash[attribute] == value
  end
  puts '-' * 40
  Main_menu.return?
end

.list_menu(data) ⇒ Object



6
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/classes/List.rb', line 6

def self.list_menu(data)
  loop do
    list_prompt = TTY::Prompt.new(active_color: :red)
    user_input = list_prompt.select("How would you like to list the Pokemon?\nPlease enter one of the following options.") do |menu|
      menu.choice 'List all', 1
      menu.choice 'List by Type', 2
      menu.choice 'List by Secondary Type', 3
      menu.choice 'List by Generation', 4
      menu.choice 'List Legendary Pokemon', 5
    end
    case user_input
    when 1
      puts '-' * 40
      puts 'Listing all Pokemon'
      puts '-' * 40
      list_all(data)
      Main_menu.return?
    when 2
      puts 'Which Type would you like to list by?'
      user_input = New.add_type
      puts '-' * 40
      puts "Listing by #{user_input} Type:"
      puts '-' * 40
      list_by(data, :type_1, user_input)
      Main_menu.return?
    when 3
      puts 'Which Secondary Type would you like to list by?'
      user_input = New.add_type
      puts '-' * 40
      puts "Listing by #{user_input} Secondary Type:"
      puts '-' * 40
      list_by(data, :type_2, user_input)
      Main_menu.return?
    when 4
      loop do
        user_input = list_prompt.ask("Which generation would you like to list by?\nInput a number between 1-8.") { |q| q.in('1-8') }
        puts '-' * 40
        puts "Listing by Generation #{user_input}"
        puts '-' * 40
        list_by(data, :generation, user_input.to_i)
        Main_menu.return?
      end
    when 5
      puts '-' * 40
      puts 'Listing Legendary Pokemon'
      puts '-' * 40
      list_by(data, :legendary, 'True')
      Main_menu.return?
    else
      puts 'Invalid selection, please enter a number between 1-5.'
    end
  end
end