Class: Umbrella::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/Umbrella/CLI.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rainObject

Returns the value of attribute rain.



2
3
4
# File 'lib/Umbrella/CLI.rb', line 2

def rain
  @rain
end

Instance Method Details

#callObject



4
5
6
7
8
9
# File 'lib/Umbrella/CLI.rb', line 4

def call 
  choose_location
  gonna_rain
  further_prompt
  choose
end

#chooseObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
# File 'lib/Umbrella/CLI.rb', line 77

def choose            
  choice = nil
  while choice != "exit"
    puts "Choose a number, type 'list' to see options again, type 'city' to change location, or 'exit' to leave."
          
          choice = gets.chomp
          
          case choice
          when "1" 
            puts ""
            puts "Weather Report:
            Temperature- #{@rain.temperature}
            Condition- #{@rain.weather_condition}
            Wind- #{@rain.wind}
            Sunrise- #{@rain.sunrise}, Sunset - #{@rain.sunset}
            "
            puts ""
          when "2"
            puts ""
            puts "#{@rain.temperature}"
            puts ""
          when "3"
            puts ""
            puts "#{@rain.weather_condition}"
            puts ""
          when "4"
            puts ""
            puts "#{@rain.wind}"
            puts ""
          when "5"
            puts ""
            puts "Sunrise- #{@rain.sunrise}, Sunset - #{@rain.sunset}"
            puts ""
          when "exit"
            puts ""
            puts "Stay dry!"
            puts ""
            exit
          when "list"
            puts "
              1) Weather Report
              2) Temperature
              3) Weather Condition
              4) Wind Speed
              5) Sunrise/Sunset

                            "
        when "city"
          call
          else
            puts "Did not understand that commmand."
          end  
    end
end

#choose_locationObject



11
12
13
14
15
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
# File 'lib/Umbrella/CLI.rb', line 11

def choose_location
  puts "Do you need an Umbrella today in:(pick a number)"
  
    ["Chicago, IL", "New York, NY", "Los Angeles, CA"].each.with_index(1){|a, i| puts "#{i}. #{a}"}
    
    input = gets.chomp.downcase 
    case input
    when "1"
      if Umbrella::Weather.find_by_city("Chicago, IL") == nil
       @rain = Umbrella::Scraper.weather_setter("Chicago+IL+USIL0225:1:US")
      else
       @rain = Umbrella::Weather.find_by_city("Chicago, IL")
      end 
       
    when "2"
        if Umbrella::Weather.find_by_city("New York, NY") == nil
       @rain = Umbrella::Scraper.weather_setter("USNY0996:1:US")
        else 
        @rain = Umbrella::Weather.find_by_city("New York, NY")
      end
        
    when "3"
      if Umbrella::Weather.find_by_city("Los Angeles, CA") == nil
      @rain = Umbrella::Scraper.weather_setter("USCA0638:1:US")
      else
      @rain = Umbrella::Weather.find_by_city("Los Angeles, CA")
    end 
    when "exit"
      puts "Stay dry!"
      exit 
    else
      puts "Please try a number 1-3."
      choose_location
    end 
end

#further_promptObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/Umbrella/CLI.rb', line 60

def further_prompt
  puts "Would you like to know more about today's weather(y/n):"
  input = gets.chomp.downcase
  if input == "y"
    puts "
      1) Weather Report
      2) Temperature
      3) Weather Condition
      4) Wind Speed
      5) Sunrise/Sunset
                        "
  else 
    puts "Stay dry!"
    exit 
  end 
end

#gonna_rainObject



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

def gonna_rain
  if @rain.rain_perc != "0%"
    puts ""
    puts "Looks like rain is in the forecast, better grab an umbrella! The chance of rain is #{@rain.rain_perc}."
    puts ""
  else
    puts ""
    puts "No rain today! Leave that umbrella at home."
    puts ""
  end 
end