Class: DailyProperties::CLI

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

Overview

CLI Controller

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
    puts "Please enter the zipcode, and I will list the most recently sold properties in that area for you: "
    zipcode = gets.strip.to_i
    list_properties(zipcode)
    menu
end

#goodbyeObject



55
56
57
58
# File 'lib/daily_properties/cli.rb', line 55

def goodbye
    puts "Thanks for trying me out. See you soon!"
    puts "--------------------------------------------------"
end

#list_properties(zipcode) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/daily_properties/cli.rb', line 17

def list_properties(zipcode)
    DailyProperties::Scraper.make_properties(zipcode)
    @properties = DailyProperties::Property.properties
    @properties.each.with_index(1) do |property, i|
        puts "#{i}. #{property.address}, #{property.sold_date}, #{property.price}"
    end
    puts "--------------------------------------------------"
end


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/daily_properties/cli.rb', line 26

def menu
    input = nil
    while input != "exit"
        puts "Enter the number of the property that you'd like to know more about, or enter 'price' to view the list sorted by sold price (high-->low), or enter 'another' to look up another zipcode, or enter 'exit': "
        input = gets.strip.downcase
        if input == "another"
            DailyProperties::Property.clear_all
            puts "--------------------------------------------------"
            call
        elsif input == "price"
            DailyProperties::Property.sort_by_price
            @properties = DailyProperties::Property.properties
            @properties.each.with_index(1) do |property, i|
                puts "#{i}. #{property.address}, #{property.sold_date}, #{property.price}"
            end
            puts "--------------------------------------------------"
        elsif input == "exit"
            goodbye
            exit
        elsif the_property = DailyProperties::Property.find(input.to_i - 1) 
            puts "#{the_property.address}, #{the_property.sold_date}, #{the_property.price}"
            puts "See more at #{the_property.url}"
        else
            puts "Not sure what you just enter."
            puts "--------------------------------------------------"
        end
    end
end

#welcomeObject



5
6
7
8
# File 'lib/daily_properties/cli.rb', line 5

def welcome
    print "Welcome! "
    call
end