Class: Madden20MarketPrices::CLI
- Inherits:
-
Object
- Object
- Madden20MarketPrices::CLI
- Defined in:
- lib/madden_20_market_prices/cli.rb
Instance Method Summary collapse
- #basic_info ⇒ Object
-
#call ⇒ Object
Greet user with a welcome message.
- #continue ⇒ Object
-
#list_choices ⇒ Object
Provide some initial direction.
-
#make_choice ⇒ Object
Ask user for input and scrape Muthead for relevant data.
- #price_info ⇒ Object
-
#print ⇒ Object
Print a numbered list of names.
- #print_expensive ⇒ Object
-
#print_gainers ⇒ Object
Use the MarketScraper class to scrape Muthead and create Player objects.
- #print_losers ⇒ Object
- #print_player(player, type) ⇒ Object
- #print_snipes ⇒ Object
- #print_trainers ⇒ Object
- #which_player ⇒ Object
Instance Method Details
#basic_info ⇒ Object
152 153 154 155 156 157 |
# File 'lib/madden_20_market_prices/cli.rb', line 152 def basic_info puts "\n---Basic Information---" puts "Player name: #{@player.name}" puts "Position and item type: #{@player.info}" puts "Overall: #{@player.ovr}\n" end |
#call ⇒ Object
Greet user with a welcome message.
5 6 7 8 9 10 |
# File 'lib/madden_20_market_prices/cli.rb', line 5 def call puts "\nWelcome to Muthead's Prices Tool." puts "" puts "What type of information are you looking for?" list_choices end |
#continue ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/madden_20_market_prices/cli.rb', line 164 def continue puts "Would you like to view more players? Please type 'yes' or 'no'." input = gets.strip if input.downcase == "y" || input.downcase == "yes" Madden20MarketPrices::Player.reset! list_choices elsif input.downcase == "n" || input.downcase == "no" puts "See you later!" else puts "\nYou must type 'yes' to see more players or type 'no' to exit." continue end end |
#list_choices ⇒ Object
Provide some initial direction.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/madden_20_market_prices/cli.rb', line 14 def list_choices puts <<~DOC 1. Market Gainers 2. Market Losers 3. Cheapest Training 4. Most Expensive Players 5. Daily Snipes DOC make_choice end |
#make_choice ⇒ Object
Ask user for input and scrape Muthead for relevant data.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/madden_20_market_prices/cli.rb', line 30 def make_choice puts "Select a number:" input = gets.strip.downcase puts "" if input == "1" puts "Here are the top 15 Market Gainers:\n" print_gainers which_player print_player(@player, "gainer") elsif input == "2" puts "Here are the top 15 Market Losers:\n" print_losers which_player print_player(@player, "loser") elsif input == "3" puts "These are the players with the best Training Points/Coins Ratio:\n" print_trainers which_player print_player(@player, "training") elsif input == "4" puts "These are the Most Expensive Players currently on the Auction House:\n" print_expensive which_player print_player(@player, "expensive") elsif input == "5" puts "Recent Auction House Snipes:\n" print_snipes which_player print_player(@player, "snipe") elsif input == "exit" puts "Womp womp." else puts "You must choose a number or type 'exit'." make_choice end end |
#price_info ⇒ Object
159 160 161 162 |
# File 'lib/madden_20_market_prices/cli.rb', line 159 def price_info puts "---Price Information---" puts "Current cost: #{@player.cost}" end |
#print ⇒ Object
Print a numbered list of names
80 81 82 |
# File 'lib/madden_20_market_prices/cli.rb', line 80 def print Madden20MarketPrices::Player.all.each.with_index { |player, index| puts "#{index + 1}. #{player.name}"} end |
#print_expensive ⇒ Object
101 102 103 104 |
# File 'lib/madden_20_market_prices/cli.rb', line 101 def print_expensive Madden20MarketPrices::MarketScraper.new.make_expensive print end |
#print_gainers ⇒ Object
Use the MarketScraper class to scrape Muthead and create Player objects.
86 87 88 89 |
# File 'lib/madden_20_market_prices/cli.rb', line 86 def print_gainers Madden20MarketPrices::MarketScraper.new.make_gainers print end |
#print_losers ⇒ Object
91 92 93 94 |
# File 'lib/madden_20_market_prices/cli.rb', line 91 def print_losers Madden20MarketPrices::MarketScraper.new.make_losers print end |
#print_player(player, type) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/madden_20_market_prices/cli.rb', line 111 def print_player(player, type) basic_info if type == "gainer" price_info puts "That's up #{player.price_change_percent} from yesterday! Sell sell sell!" elsif type == "loser" price_info if "#{player.price_change_percent}" != "None --" puts "That's down #{player.price_change_percent} from yesterday. Ouch." else puts "This item is too new for accurate price change information." end elsif type == "training" price_info puts "Whoa! This item only costs #{player.price_change_percent} coins per Training Point! Quicksell immediately." elsif type == "expensive" price_info if "#{player.price_change_percent}" != "--" puts "That's a #{player.price_change_percent} change in price from yesterday." else puts "This item is too new for accurate price change information." end elsif type == "snipe" puts "Somebody sniped this item for #{player.cost} coins! Are you kidding me?!" end puts "" continue end |
#print_snipes ⇒ Object
106 107 108 109 |
# File 'lib/madden_20_market_prices/cli.rb', line 106 def print_snipes Madden20MarketPrices::MarketScraper.new.make_snipes print end |
#print_trainers ⇒ Object
96 97 98 99 |
# File 'lib/madden_20_market_prices/cli.rb', line 96 def print_trainers Madden20MarketPrices::MarketScraper.new.make_trainers print end |
#which_player ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/madden_20_market_prices/cli.rb', line 140 def which_player puts "\nWhich player would you like to know more about?" input = gets.strip if input.to_i.between?(1, Madden20MarketPrices::Player.all.length) @player = Madden20MarketPrices::Player.find(input.to_i) else puts "You must type the number that corresponds with your selection." which_player end end |