Class: MostHauntedCli::CLI

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

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



3
4
5
6
# File 'lib/most_haunted/cli.rb', line 3

def initialize
    MostHauntedCli::Scraper.scrape_america
    MostHauntedCli::Scraper.states
end

Instance Method Details

#america_descriptionsObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/most_haunted/cli.rb', line 101

def america_descriptions
    input = nil
    while input != "exit"
        puts "--" * 30
        puts  <<-DOC.gsub /^\s*/, ''
        
        * choose an index (1-10) for more information on a location
        * 'list' for the 10 Most Haunted Places in America
        * 'main menu' 
        * 'exit'
        DOC
        input = gets.strip.downcase
            
        if input.to_i > 0 && input.to_i < 11
            puts ''
            MostHauntedCli::America.america_descriptions(MostHauntedCli::America.indexes[input.to_i-1])
        elsif input == "list"
            puts ''
            MostHauntedCli::America.list_locations
        elsif input == "main menu"
            start
        elsif input == 'exit' 
            goodbye
            exit
        else
            puts ''
            puts "** Please enter valid input **" 
            america_descriptions
        end
    end
end

#callObject



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

def call
    puts "--" * 17
    puts "Search for Scary Places Near You!" 
    puts "--" * 17
    start
    goodbye
end

#goodbyeObject



133
134
135
136
# File 'lib/most_haunted/cli.rb', line 133

def goodbye
    puts ''
    puts "Scare ya later!"
end

#list_americaObject



56
57
58
59
# File 'lib/most_haunted/cli.rb', line 56

def list_america 
    puts ''
    MostHauntedCli::America.list_locations
end

#list_statesObject



61
62
63
# File 'lib/most_haunted/cli.rb', line 61

def list_states
    MostHauntedCli::States.state_columns
end

#startObject



16
17
18
19
20
21
22
23
24
25
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
54
# File 'lib/most_haunted/cli.rb', line 16

def start
    puts ''
    puts <<-DOC.gsub /^\s*/, ''
    
        1. Most Haunted Places in America
        2. Choose a State
    DOC
    
    input = nil
    puts ''
    while input != "exit"
        puts "--" * 17
        puts "Please enter '1', '2', or 'exit'"
        puts "" 
        input = gets.strip.downcase
        
        case input
        when "1"
            puts "--" * 17
            puts "10 Most Haunted Places in America"
            puts "--" * 17
            puts ""
            sleep(2)
            list_america
            america_descriptions
        when "2"
            puts ""
            list_states
            state_options
        when "exit"
            goodbye
            exit
        else
            puts ''
            puts "** Please enter valid input **"
            start
        end
    end
end

#state_optionsObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/most_haunted/cli.rb', line 65

def state_options
    input = nil
    while input != "exit"
    puts "--" * 30
        puts <<-DOC.gsub /^\s*/, ''
        
        * choose an index (1-52) to discover the state's most haunted locations!
        * 'list' for a list of states
        * 'main menu'
        * 'exit'
        
        DOC
        input= gets.strip.downcase
        
        if input.to_i > 0 && input.to_i < 53
            puts "--" * 20
            MostHauntedCli::Scraper.scrape_state_title(input.to_i)
            puts "--" * 20
            puts ''
            MostHauntedCli::States.open_state_info(input.to_i)
        elsif input == 'main menu'
            start
        elsif input == 'list'
            puts ''
            MostHauntedCli::States.state_columns
        elsif input == 'exit'
            goodbye
            exit
        else
            puts ''
            puts "** Please enter valid input **"
            state_options
        end
    end
end