weatherfetch 0.0.3 → 0.0.4

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
  SHA256:
3
- metadata.gz: adf062366579620ac82e2d599cd7f162be4b134d7fa011185d52fc0a548b0002
4
- data.tar.gz: dacd56d05c3c1e17f07dde431dad3c1f95bf83361e795c8113e998f91cad7aa3
3
+ metadata.gz: d07efd25e4be1cd983bcda4169cf7fe0180f78c287d5cf251925e437f89ad8fa
4
+ data.tar.gz: 5fdd836833b35e52e93599bca127e663cbaf2944392a137027e67ccf5e2eb1e5
5
5
  SHA512:
6
- metadata.gz: 48e0fbf3dc2ef9e3b6c41e25981c915ad6758a0e4e9c99b70ca17e9a409adbe33ce8514fdef7739121733b63965b718ef2d03517f86bbaeb0d37da833f54b49d
7
- data.tar.gz: 73101963a77f63414fd5934030a5a6d5af47b38f8f86083a7c48f5b174db3f8c53150fa0181f761f3981f4ba9a1082a948a30c17bff84ccf2ac9fc8e4bc18acd
6
+ metadata.gz: c7577a516a7e3f934eb9524812814a8f6b5c417c2e5631c2bc8e94557086224da895d60f7cad7ac26387e30480c57bd0b6da07e2bf53f48f5ec033876d5ec9e4
7
+ data.tar.gz: c76bec63c2522b511db4c4004056f61545889edce7ff5dc53de781524e999ee6821074e4c006ce643dd23c300c77e6f8a3488789fd4fb513175dcb592f77d40a
@@ -27,7 +27,7 @@ module WeatherFetch
27
27
  table = Terminal::Table.new(
28
28
  headings: create_headings(['Hour', 'Actual', 'Feels Like', 'Conditions', 'Humidity']),
29
29
  rows: rows,
30
- title: "🌧 #{Rainbow(location.capitalize).cornflower} 🌞"
30
+ title: "#{Rainbow(get_title).cornflower}"
31
31
  )
32
32
 
33
33
  puts table
@@ -54,7 +54,7 @@ module WeatherFetch
54
54
  table = Terminal::Table.new do |t|
55
55
  t.headings = create_headings(['Date', 'Min', 'Max', 'Morning', 'Afternoon', 'Evening', 'Night', 'Conditions', 'Humidity'])
56
56
  t.rows = rows
57
- t.title = "🌧 #{Rainbow(location.capitalize).cornflower} 🌞"
57
+ t.title = "#{Rainbow(get_title).cornflower}"
58
58
  t.style = { all_separators: :true }
59
59
  end
60
60
 
@@ -66,23 +66,43 @@ module WeatherFetch
66
66
  headings.map { |h| Rainbow(h).red }
67
67
  end
68
68
 
69
- def fetch_location_data(location, type)
70
- latitude, longitude = Geocoder.search(location).first.coordinates
69
+ def get_title
70
+ city = @location_data.data.dig('address', 'city')
71
+ country = @location_data.data.dig('address', 'country_code').upcase
72
+ state = @location_data.data.dig('address', 'state')
73
+
74
+ cleaned_city = city && city.split('-').first
75
+ flag = country.tr('A-Z', "\u{1F1E6}-\u{1F1FF}")
71
76
 
72
- exclusions = ['hourly', 'minutely', 'current', 'daily'].reject do |ex|
73
- ex == type
77
+ title = [cleaned_city, state, country].each_with_object('') do |loc, str|
78
+ str << "#{loc}, " if loc
74
79
  end
75
80
 
76
- options = {
77
- query: {
78
- lat: latitude,
79
- lon: longitude,
80
- exclude: exclusions.join(','),
81
- units: 'imperial',
82
- appid: 'c8d7f5fd25b8914cc543ed45e6a40bba'
81
+ "#{flag} #{title.delete_suffix(', ')} #{flag}"
82
+ end
83
+
84
+ def fetch_location_data(location, type)
85
+ if @location_data = Geocoder.search(location).first
86
+ latitude, longitude = @location_data.coordinates
87
+
88
+ exclusions = ['hourly', 'minutely', 'current', 'daily'].reject do |ex|
89
+ ex == type
90
+ end
91
+
92
+ options = {
93
+ query: {
94
+ lat: latitude,
95
+ lon: longitude,
96
+ exclude: exclusions.join(','),
97
+ units: 'imperial',
98
+ appid: 'c8d7f5fd25b8914cc543ed45e6a40bba'
99
+ }
83
100
  }
84
- }
85
- response = HTTParty.get('http://api.openweathermap.org/data/2.5/onecall', options)
101
+ response = HTTParty.get('http://api.openweathermap.org/data/2.5/onecall', options)
102
+ else
103
+ puts Rainbow('Please enter a valid location').red
104
+ exit
105
+ end
86
106
  end
87
107
  end
88
108
  end
@@ -1,3 +1,3 @@
1
1
  module WeatherFetch
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weatherfetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Andrews