class Apartmenthunter::CLI
Attributes
area[RW]
bathrooms[RW]
bedrooms[RW]
max_price[RW]
miles[RW]
min_price[RW]
results[RW]
zip[RW]
Public Instance Methods
csv_export()
click to toggle source
# File lib/apartmenthunter/cli.rb, line 76 def csv_export Export.output(@apt_results) say("\nYour results are located in the file aptsearchresults.csv your Documents folder") post_search_options end
display_results()
click to toggle source
# File lib/apartmenthunter/cli.rb, line 54 def display_results Formatador.display_compact_table(@apt_results) end
goodbye()
click to toggle source
# File lib/apartmenthunter/cli.rb, line 82 def goodbye puts "\nHappy apartment hunting!\n" exit end
locate()
click to toggle source
# File lib/apartmenthunter/cli.rb, line 26 def locate @locations = ["All of the Greater New York area", "New Jersey", "Bronx", "Brooklyn", "Fairfield", "Long Island", "Manhattan", "Queens", "Staten Island", "Westchester", "Exit"] choose do |menu| menu.layout = :list menu.prompt = "\nPlease enter your the specific area you would like to search : ".green menu.choices(*@locations) {|command| command == "Exit" ? goodbye : current_area = Area.new(command)} end end
parameters()
click to toggle source
# File lib/apartmenthunter/cli.rb, line 35 def parameters say("\nPlease begin by answering a few questions to narrow down your search.".red) @min_price = ask("What is the minimum amount of rent you would like to pay? ", lambda { |p| p.sub(/[^0-9A-Za-z]/, '')}) @max_price = ask("What is the maximum amount of rent you would like to pay? ", lambda { |p| p.sub(/[^0-9A-Za-z]/, '')}) @bedrooms = ask("Please enter the number of bedrooms (between 1 and 8): ", Integer) { |q| q.in = 0..8 } @bathrooms = ask("Please enter the number of bathrooms (between 1 and 8): ", Integer) { |q| q.in = 0..8 } @zip = ask("Please enter the 5 digit zip code you would like to center your search around : ", String) do |q| q.validate = /\A\d{5}(?:-?\d{4})?\Z/ q.responses[:not_valid] = "Please enter a 5 digit zip code." end @miles = ask("Finally, please enter the number of miles (between 0 and 500) you would like to search from that zip code : ", Integer) { |q| q.in = 0..500 } end
post_search_options()
click to toggle source
# File lib/apartmenthunter/cli.rb, line 58 def post_search_options say("\nPlease select wether you would like to export these results, restart your search, or quit : \n".green) loop do choose do |menu| menu.layout = :list menu.choice("Export Results") do |command| csv_export end menu.choice("Restart Search") do |command| Apartmenthunter::Run.new.call end menu.choice("Exit") do |command| goodbye end end end end
welcome()
click to toggle source
# File lib/apartmenthunter/cli.rb, line 16 def welcome puts %q[ _ _ _ _ _ _ /_\ _ __ __ _ _ _| |_ _ __ ___ _ _| |_ | || |_ _ _ _| |_ ___ _ _ / _ \| '_ \/ _` | '_| _| ' \/ -_) ' \ _| | __ | || | ' \ _/ -_) '_| /_/ \_\ .__/\__,_|_| \__|_|_|_\___|_||_\__| |_||_|\_,_|_||_\__\___|_| |_| ].green.bold puts "\nThis handy gem will help you find apartments availible for rent on Craigslist in the Greater New York area.\n".green.bold end