Class: LocalRealEstate::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/local_real_estate/cli.rb

Instance Method Summary collapse

Instance Method Details

#callObject



2
3
4
5
# File 'lib/local_real_estate/cli.rb', line 2

def call
  greeting
  menu
end

#detail_menuObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/local_real_estate/cli.rb', line 22

def detail_menu
  print_listings
  puts 'To see more info on a listing, please select a number from the list above:'
  detailed_view(gets.strip)
  puts 'To go back to the previous list type "back". Or "new" to start a new search by zip. To quit, type "exit"'
  input = gets.strip.downcase
  case input
  when 'back'
    detail_menu
  when 'new'
    menu
  when 'exit'
    goodbye
  else 
    invalid_input
  end
end

#detailed_view(selection) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/local_real_estate/cli.rb', line 46

def detailed_view(selection)
  home = LocalRealEstate::Listing.all[selection.to_i - 1]
  puts '-------------------------------------------'
  puts "Address: #{home.address}. #{home.city},#{home.state}."
  puts "Price: #{home.price}"
  puts "Bedrooms:#{home.bedrooms}"
  puts "Bathrooms: #{home.bathrooms}"
  unless home.sqft == '' then puts "Square Feet: #{home.sqft}" end
  unless home.lot_size == '' then puts "Lot Size #{home.lot_size}" end
  unless home.cars == '' then puts "Garage: #{home.cars}" end
  puts '-------------------------------------------'
end

#goodbyeObject



79
80
81
# File 'lib/local_real_estate/cli.rb', line 79

def goodbye
  puts 'See you next time!'
end

#greetingObject



7
8
9
10
11
12
13
14
15
# File 'lib/local_real_estate/cli.rb', line 7

def greeting
  system 'clear'
  puts '-------------------------------------------'
  puts '-------------------------------------------'
  puts 'Welcome to the Local Real Estate Listing app'
  puts 'This will display local real estate listings by'
  puts 'zip code and allow you to see expanded details on each listing'
  puts ''
end

#invalid_inputObject



71
72
73
74
75
76
77
# File 'lib/local_real_estate/cli.rb', line 71

def invalid_input
  puts ' -  -  -  -  -  -  -  -  -  -  -  -  - '
  puts 'Input not recognized, please try again:'
  puts ' -  -  -  -  -  -  -  -  -  -  -  -  - '
  sleep 2
  detail_menu
end


17
18
19
20
# File 'lib/local_real_estate/cli.rb', line 17

def menu
  new_search
  detail_menu
end

#new_searchObject



40
41
42
43
44
# File 'lib/local_real_estate/cli.rb', line 40

def new_search
  LocalRealEstate::Listing.all.clear
  puts 'Please type in the Zip code in which you would like to search'
  zip_method
end


63
64
65
66
67
68
69
# File 'lib/local_real_estate/cli.rb', line 63

def print_listings
  puts "--------Listings in #{LocalRealEstate::Listing.current_city}--------"
  LocalRealEstate::Listing.all.each_with_index do |listing, i|
    puts "#{i + 1}. #{listing.address} - #{listing.bedrooms} #{listing.price}"
  end
  puts '-------------------------------------------'
end

#zip_methodObject



59
60
61
# File 'lib/local_real_estate/cli.rb', line 59

def zip_method
  LocalRealEstate::Scraper.new(gets.strip).create_listings
end