class Apartments::CLI
Public Instance Methods
call()
click to toggle source
# File lib/apartments/cli.rb, line 3 def call Apartments::Scraper.new.make_apartments puts "Welcome to the latest listing of NY area Apartments. Hit 'Enter' to continue" gets start end
print_apartment(apartment)
click to toggle source
# File lib/apartments/cli.rb, line 46 def print_apartment(apartment) puts "" puts "----- #{apartment.title} -----" puts "" puts "bedrooms / area: #{apartment.area}" puts "rental price: #{apartment.price}" puts "neighborhood: #{apartment.neighborhood}" puts "date advertised: #{apartment.date}" puts "apartment url: #{apartment.url}" puts "" puts "----------------------------- Description -----------------------------" puts "#{apartment.description}" puts "" end
print_apartments()
click to toggle source
# File lib/apartments/cli.rb, line 61 def print_apartments puts "" puts "----------------------------- Apartments -----------------------------" puts "" Apartments::Apartment.all.each.with_index(1) do |apartment, idx| spacer = apartment.price.nil? ? [' '].cycle(20).to_a.join("") : [' '].cycle(20 - apartment.price.length).to_a.join("") puts "#{idx}.\t #{apartment.price} #{spacer}\t #{apartment.neighborhood}" end end
see_another?()
click to toggle source
# File lib/apartments/cli.rb, line 28 def see_another? puts "" puts "Would you like to see another apartment? (Y/N)" input = gets.strip.upcase if input == "Y" start elsif input == "N" puts "" puts "Good luck in your apartment search. Have a nice day!" exit else puts "" puts "Not sure what you have in mind.." see_another? end end
select_apartment()
click to toggle source
# File lib/apartments/cli.rb, line 16 def select_apartment puts "" input = nil while input.nil? || !input.between?(1,Apartments::Apartment.count) puts "which apartment would you like to have more information about?" input = gets.strip.to_i end apartment = Apartments::Apartment.find(input.to_i) print_apartment(apartment) end
start()
click to toggle source
# File lib/apartments/cli.rb, line 10 def start print_apartments select_apartment see_another? end