Class: Apartments::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
7
8
# 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


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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


61
62
63
64
65
66
67
68
69
# 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?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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_apartmentObject



16
17
18
19
20
21
22
23
24
25
# 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

#startObject



10
11
12
13
14
# File 'lib/apartments/cli.rb', line 10

def start
  print_apartments
  select_apartment
  see_another?
end