masonellwood_cli_app_two 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c33665250b15469ecaaca7f25159980f8b65672
4
- data.tar.gz: e843819d45ada343f93196865bc1d3872ad25681
3
+ metadata.gz: 4ad776e66245d9f40cf8f7cb7f2077d05d540ac0
4
+ data.tar.gz: 9bf0c9aacd0dedeffd74b17a1e31e26c29fe4c25
5
5
  SHA512:
6
- metadata.gz: 480fde390aea2001c029264cf0d5828954b04dd5030c5a362b4d7d19005fa57b5232450ff712483589b16d3908adb626ebcc87b234813425a4ed0633e12e7778
7
- data.tar.gz: fd00fd5b0d3db368fd879dc6186e316150a66c4addb827d99a3ebfcaa496dc85e6f7042d9d295cf1ae9cc62adb7f29c02eca0ba329d4936c26c0ab39ccc7b789
6
+ metadata.gz: fa12bc769421fc0a5026f7cc583c7085788cef33f79ff2a6c22593e3e517aa0146462e8d136a81e213dbf3cfa4be6c0c31db3126e2fc0b15217feb8f99e0b554
7
+ data.tar.gz: 908040f4443678f44f3f377ec4dfd9bb1c1127001714d0bb300301a7bf474b153adfc808d3890973c705626e9802ea6008579dfd3893cdae0e1e35a83e6bc0a7
data/bin/weather-channel CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "masonellwood_cli_app_two"
4
+ require_relative "../lib/masonellwood_cli_app_two"
5
5
 
6
6
  MasonellwoodCliAppTwo::CLI.new.call
@@ -0,0 +1,7 @@
1
+ class MasonellwoodCliAppTwo::City
2
+ attr_accessor :name, :url
3
+ def initialize(name, url)
4
+ @url = url
5
+ @name = name
6
+ end
7
+ end
@@ -1,7 +1,8 @@
1
1
  class MasonellwoodCliAppTwo::CLI
2
2
 
3
3
  attr_accessor :state_info
4
-
4
+ EVERY_STATE = ["alabama", "alaska", "arizona", "arkansas", "california", "colorado", "connecticut", "delaware", "florida", "georgia", "hawaii", "idaho", "illinois", "indiana", "iowa", "kansas", "kentucky", "louisiana", "maine", "maryland", "massachusetts", "michigan", "minnesota", "mississippi", "missouri", "montana", "nebraska", "nevada", "new hampshire", "new jersey", "new mexico", "new york", "north carolina", "north dakota", "ohio", "oklahoma", "oregon", "pennsylvania", "rhode island",
5
+ "south carolina", "south dakota", "tennessee", "texas", "utah", "vermont", "virginia", "washington", "west virginia", "wisconsin", "wyoming" ]
5
6
  def call
6
7
  greet_with_prompt
7
8
  set_up_instance_variable
@@ -13,15 +14,13 @@ class MasonellwoodCliAppTwo::CLI
13
14
  end
14
15
 
15
16
  def set_up_instance_variable
16
- every_state = ["alabama", "alaska", "arizona", "arkansas", "california", "colorado", "connecticut", "delaware", "florida", "georgia", "hawaii", "idaho", "illinois", "indiana", "iowa", "kansas", "kentucky", "louisiana", "maine", "maryland", "massachusetts", "michigan", "minnesota", "mississippi", "missouri", "montana", "nebraska", "nevada", "new hampshire", "new jersey", "new mexico", "new york", "north carolina", "north dakota", "ohio", "oklahoma", "oregon", "pennsylvania", "rhode island",
17
- "south carolina", "south dakota", "tennessee", "texas", "utah", "vermont", "virginia", "washington", "west virginia", "wisconsin", "wyoming" ]
18
17
  puts "Please type your State of interest."
19
18
  puts "If you forgot how to spell some of the state names, just type states."
20
19
  puts "If you don't care about the weather today, just type exit."
21
20
  state = nil
22
21
  while state != "exit"
23
22
  state = gets.strip.downcase
24
- if every_state.include?(state)
23
+ if EVERY_STATE.include?(state)
25
24
  @state_info = MasonellwoodCliAppTwo::StateScraper.new(state)
26
25
  @state_info.scrape_cities
27
26
  display_citie_option
@@ -33,7 +32,7 @@ class MasonellwoodCliAppTwo::CLI
33
32
  puts "#{index}. #{the_state.capitalize}"
34
33
  end
35
34
  puts "Here are all the valid States, which one would you like to know the weather?"
36
- elsif every_state.include?(state) == false && state != "states" && state != "exit"
35
+ elsif state != "exit"
37
36
  puts "Not sure what you want bud. Please type exit to quit. Or see the valid states by typing states."
38
37
  end
39
38
  end
@@ -44,52 +43,31 @@ class MasonellwoodCliAppTwo::CLI
44
43
  puts "Here are all of the cities in #{@state_info.state.capitalize}!"
45
44
  @state_info.cities.each_with_index.each do |city, index|
46
45
  index += 1
47
- citys = city.split(/ : /)
48
- puts "#{index}: #{citys[0]}"
46
+ puts "#{index}: #{city.name}"
49
47
  end
50
48
  display_city_weather
51
49
  end
52
50
 
53
51
  def display_city_weather
54
- puts "Now type the name of the city you want to know the weather of."
52
+ puts "Enter the number of the city you want to view"
55
53
  input = nil
56
- array = []
57
- @state_info.cities.each_with_index.each do |city, index|
58
- index += 1
59
- city = city.split(/ : /)
60
- array << city[0].downcase
61
- end
62
54
  while input != "exit"
63
55
  input = gets.strip.downcase
64
56
  if input == "cities"
65
57
  @state_info.cities.each_with_index.each do |city, index|
66
- index += 1
67
- city = city.split(/ : /)
68
- puts "#{index}: #{city[0]}"
69
- end
58
+ index += 1
59
+ puts "#{index}: #{city.name}"
60
+ end
70
61
  puts "Now type the name of the city you want to know the weather of."
71
- elsif array.include?(input)
72
- @state_info.city_weather(input)
62
+ elsif input.to_i.between?(1, @state_info.cities.size)
63
+ city = @state_info.cities[input.to_i - 1]
64
+ @state_info.city_weather(city)
73
65
  elsif input != "exit"
74
66
  puts "Please type a valid city, or type exit."
75
67
  end
76
68
  end
77
69
  end
78
70
 
79
- def another_state
80
- puts "would you like to check a different state? Type yes or no."
81
- input = nil
82
- input = gets.strip.downcase
83
- case input
84
- when "yes"
85
- set_up_instance_variable
86
- when "no"
87
- goodbye
88
- else
89
- puts "Please type yes or no"
90
- end
91
- end
92
-
93
71
  def goodbye
94
72
  puts "See you tomorrow for more weather reports!"
95
73
  end
@@ -3,37 +3,30 @@ class MasonellwoodCliAppTwo::StateScraper
3
3
 
4
4
  def initialize(state)
5
5
  @state = state
6
+ @cities = []
6
7
  end
7
8
 
8
9
  def scrape_cities
9
10
  html = open("https://www.wunderground.com/cgi-bin/findweather/getForecast?query=#{@state}") #pulls html
10
11
  student_file = Nokogiri::HTML(html)
11
- cities_array = []
12
12
  student_file.css("tbody tr").each do |x|
13
13
  city = x.css("a").text
14
14
  url = x.search("a").attr("href").value
15
- cities_array << "#{city} : #{url}"
15
+ new_city = MasonellwoodCliAppTwo::City.new(city, url)
16
+ @cities << new_city
16
17
  end
17
- @cities = cities_array
18
18
  end
19
19
 
20
- def city_weather(input)
21
- input_city = input
22
- self.cities.each do |x|
23
- citys = x.split(/ : /)
24
- downcase_city = citys[0].downcase
25
- if downcase_city == input_city
26
- html = open("https://www.wunderground.com/#{citys[1]}") #pulls html
20
+ def city_weather(city)
21
+ html = open("https://www.wunderground.com/#{city.url}") #pulls html
27
22
  student_file = Nokogiri::HTML(html)
28
23
  weather_conditions = student_file.css("#curCond .wx-value").text
29
24
  temperature = student_file.css("#curTemp .wx-value").text
30
- puts "It looks like you are interested in beautiful #{input_city.capitalize}!"
25
+ puts "It looks like you are interested in beautiful #{city.name}!"
31
26
  puts "Weather Conditions for Today: #{weather_conditions}"
32
27
  puts "Current Temperature: #{temperature} Degrees Fahrenheit"
33
- puts "Check more or the Cities in your area by typing the City name."
28
+ puts "Check more or the Cities in your area by typing the Number Name."
34
29
  puts "If you want to see all the Cities again, type Cities."
35
30
  puts "Or type exit."
36
- end
37
- end
38
31
  end
39
32
  end
@@ -1,3 +1,3 @@
1
1
  module MasonellwoodCliAppTwo
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,6 +1,8 @@
1
1
  require "nokogiri"
2
2
  require 'open-uri'
3
+ require 'pry'
3
4
 
4
5
  require "masonellwood_cli_app_two/version"
5
6
  require_relative './masonellwood_cli_app_two/cli'
6
7
  require_relative './masonellwood_cli_app_two/state-scraper'
8
+ require_relative './masonellwood_cli_app_two/city'
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: masonellwood_cli_app_two
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mason Ellwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-13 00:00:00.000000000 Z
11
+ date: 2017-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,9 +102,12 @@ files:
102
102
  - bin/setup
103
103
  - bin/weather-channel
104
104
  - lib/masonellwood_cli_app_two.rb
105
+ - lib/masonellwood_cli_app_two/city.rb
105
106
  - lib/masonellwood_cli_app_two/cli.rb
106
107
  - lib/masonellwood_cli_app_two/state-scraper.rb
107
108
  - lib/masonellwood_cli_app_two/version.rb
109
+ - masonellwood_cli_app_two-0.1.0.gem
110
+ - masonellwood_cli_app_two-0.1.1.gem
108
111
  - masonellwood_cli_app_two.gemspec
109
112
  homepage: https://github.com/MasonEllwood/masonellwood_cli_app_two
110
113
  licenses: