Class: ListScraper::CLI

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

Instance Method Summary collapse

Instance Method Details

#list_updateObject



91
92
93
94
# File 'lib/storeListScraper/cli.rb', line 91

def list_update
    puts "\n⊙﹏⊙\nRunning update, this could take several minutes.."
    ListScraper::UpdateScraper.new
end

#list_viewObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/storeListScraper/cli.rb', line 53

def list_view
    puts "\nThis is a list of 27,000+ businesses,\nHow would you like to view it?\n1) select a letter group\n2) search a keyword\n3) return to main menu"
    case gets.strip.to_i
    when 1
        puts "Please type letter(s) you want at the START of the business name:"
        ListScraper::CSVmanager.list_view_by_letter(gets.strip)
        menu
    when 2
        puts "Please type the keyword as you expect to see it in the business name.\n(example: 'Jimmy's Pizza' contains 'Pizza'"
        ListScraper::CSVmanager.list_view_by_search(gets.strip)
        menu
    when 3
        menu
    else
        puts "\n(ರ_ರ)\nThat is not a valid input.."
        list_view
    end
end


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/storeListScraper/cli.rb', line 9

def menu
    puts "\nWhat are we interested in accomplishing today?\n1) New Scrape\n2) View Business List\n3) Update Business List\n4) Exit Program\n"
    case gets.strip.to_i
    when 1
        new_scrape
    when 2
        list_view
    when 3
        list_update
    when 4
        puts "\n(⌐■_■)ノ\nGoodbye friend!\n"
        exit
    else
        puts "\n(ರ_ರ)\nThat is not a valid input.."
        menu
    end
end

#name_checkObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/storeListScraper/cli.rb', line 32

def name_check
    input = gets.strip
    case input
    when "list"
        list_view
    when "menu"
        menu
    else  
        #check business list for name
        link = ListScraper::CSVmanager.business_list_check(input)
        if link != nil
            puts "\n( ゚ヮ゚)\nFound the business! Want me to scrape a list? (y/n)"
            confimation = gets.strip
            confimation == 'y' ? scrape(link) : exit
        else
            puts "\n(●_●)\nSorry, but it doesn't look like that's on the list.\nPlease enter another name\nOR type 'list' to view my Business List\nOR type 'menu' to return to the main menu"
            name_check
        end
    end
end

#new_scrapeObject



27
28
29
30
# File 'lib/storeListScraper/cli.rb', line 27

def new_scrape
    puts "\n(∪ ◡ ∪)\nSo you want to run a scrape?\nPlease type a company name as found in my Business List.\nOR type 'list' to view the Business List\nOr 'menu' to return to the main menu"
    name_check
end

#scrape(link) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/storeListScraper/cli.rb', line 72

def scrape(link)
    a = ListScraper::LocationScraper.new("#{ListScraper::LocationScraper.base}#{link}")
    a.page_scrape(a.link)
    a.clean_out
    puts "\n( ◕‿◕)\nI found #{a.loc_pages.length} locations across #{a.state_pages.length}for this business.\nWould you like to export? (y/n)"
    confirmation = gets.strip
    if confirmation == 'y'
        puts "\n(°ロ°)☝\nWhat would you like to name the file?"
        fileName = gets.strip
        puts "...\n( ◉_◉)\nExporting now, this can take awhile. I will alert when done."
        a.create_stores
        ListScraper::CSVmanager.locations_export(fileName)
        puts "Export Completed Successfully!"
    else
        puts "\n(⌐■_■)ノ\nI hope you have a great day!\nGoodbye"
        exit
    end
end

#startObject

greet user with menu



4
5
6
7
# File 'lib/storeListScraper/cli.rb', line 4

def start #greet user with menu
    puts "\nHello user! ヽ(‘ ∇‘ )ノ"
    menu
end