Class: CommandLineInterface
- Inherits:
-
Object
- Object
- CommandLineInterface
- Defined in:
- lib/command_line_interface.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #basic_info ⇒ Object
- #display ⇒ Object
- #display_more_info ⇒ Object
- #goodbye ⇒ Object
-
#initialize ⇒ CommandLineInterface
constructor
A new instance of CommandLineInterface.
- #more_info ⇒ Object
- #proccess ⇒ Object
- #valid?(zip_code) ⇒ Boolean
- #welcome ⇒ Object
Constructor Details
#initialize ⇒ CommandLineInterface
Returns a new instance of CommandLineInterface.
11 12 13 14 |
# File 'lib/command_line_interface.rb', line 11 def initialize welcome proccess end |
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/command_line_interface.rb', line 9 def url @url end |
Instance Method Details
#basic_info ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/command_line_interface.rb', line 75 def basic_info puts "You can now enter your zip code." the_user_zip_code = gets.strip while !valid?(the_user_zip_code) do puts "Please enter a valid zip code" the_user_zip_code = gets.strip end url ="https://www.gasbuddy.com/home?search=#{the_user_zip_code}&fuel=1" gas_stations = Scraper.scraper_the_cheapest_nearby(url) Gas_station.create_gas_station_from_data(gas_stations) display end |
#display ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/command_line_interface.rb', line 61 def display Gas_station.all.each do |gas_station| puts "=====================================================================================".colorize(:blue) puts "Gas Station: ".colorize(:green) + "#{gas_station.name}".colorize(:yellow) puts "price: ".colorize(:green) + "#{gas_station.price}".colorize(:yellow) puts "Gas Address: ".colorize(:green) + "#{gas_station.address}".colorize(:yellow) puts "=====================================================================================".colorize(:blue) puts "" puts "" puts "" end end |
#display_more_info ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/command_line_interface.rb', line 99 def display_more_info Gas_station.all.each do |gas_station| puts "=====================================================================================".colorize(:blue) puts "Gas Station: ".colorize(:green) + "#{gas_station.name}".colorize(:yellow) puts "Price: ".colorize(:green) + "#{gas_station.price}".colorize(:yellow) gas_station.new_array.each do |el| puts "--------------------------------------------------------------------------------------" puts " Type of Gas: ".colorize(:green) + "#{el[:type_of_gas]}".colorize(:yellow) puts " Price of Gas: ".colorize(:green) + "#{el[:price_of_gas]}".colorize(:yellow) puts " Last Reported: ".colorize(:green) + "#{el[:last_report]}".colorize(:yellow) puts "--------------------------------------------------------------------------------------" end puts "Overall Rating: ".colorize(:green) + "#{gas_station.}".colorize(:yellow) puts "Gas Address: ".colorize(:green) + "#{gas_station.address}".colorize(:yellow) puts "=====================================================================================".colorize(:blue) puts "" puts "" puts "" end end |
#goodbye ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/command_line_interface.rb', line 50 def goodbye puts "--------------------------------------------------".colorize(:light_blue) puts "| |".colorize(:light_blue) puts "| Goodbye!!!!! |".colorize(:light_blue) puts "| |".colorize(:light_blue) puts "--------------------------------------------------".colorize(:light_blue) puts "" puts "" end |
#more_info ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/command_line_interface.rb', line 90 def more_info Gas_station.all.each do |gas_station| new_info = Scraper.scraper_detailled_info("https://www.gasbuddy.com#{gas_station.detail_url}") gas_station.add_more_info(new_info) end display_more_info end |
#proccess ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/command_line_interface.rb', line 28 def proccess puts "Would like to see the cheapest gas stations near you? (yes/no)" answer_to_zip_code = gets.strip if ["YES","Y"].include?(answer_to_zip_code.upcase) basic_info puts "Would you like more information? (yes/no)" more_info_answer = gets.strip ["YES","Y"].include?(more_info_answer.upcase) ? more_info : goodbye else goodbye end end |
#valid?(zip_code) ⇒ Boolean
45 46 47 |
# File 'lib/command_line_interface.rb', line 45 def valid?(zip_code) true if zip_code.to_i != 0 && zip_code.length == 5 end |
#welcome ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/command_line_interface.rb', line 17 def welcome puts "--------------------------------------------------".colorize(:light_blue) puts "| |".colorize(:light_blue) puts "| Welcome To Our Wonderful CLI |".colorize(:light_blue) puts "| |".colorize(:light_blue) puts "--------------------------------------------------".colorize(:light_blue) puts "" puts "" end |