kovid 0.4.5 β†’ 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96bc2442058a29c4830dbebb1baedc428f220b2b20762b150fa1ccd658648d4e
4
- data.tar.gz: 11454ce4ed1f2c48778141e886cc8f9a86d8d1a3efb66caaa302f86586a17ec1
3
+ metadata.gz: 851facd4cdf0be330b04c5e0f81c91d8a5c5fdaea314751540d224e108c4464d
4
+ data.tar.gz: b36ce66c70a12df6930ca30d78ccf7628b06d6a4c70563e6382a8db584d96e6a
5
5
  SHA512:
6
- metadata.gz: 45f3d74148f5807f9ef03ec5a4405d9aa337ddb98e7c54e8180fab64c31ce1ff9bc92ed4840f3287514046c926d1ffb5e6982a5048a7ea16e13fe15e3b210a64
7
- data.tar.gz: 29654bae42cd1c257b2705554e7b7effd1fdde060bbd31bf3a413a4a120f4ef6187117af84bdba6d16c19b361cfcaa02d0e8013911a8d31922c99b6f0bc427ba
6
+ metadata.gz: 7ef46bb27fef43b9e032dfc81cb05389b22cd199a46f5d0c354794f892552aefb9bc765cc0fde64145e75961086622e29a06de057cc6acb66c192b46c9438890
7
+ data.tar.gz: f0e2aad02999132f9505586886545116c915d98b90701b6a8f98410b0c27ca64c8990cfe841c75c2096c5023cc11bd0922eafa0ac0258f5e7de3f8e0dd31ede1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.4.4)
4
+ kovid (0.4.5)
5
5
  ascii_charts (~> 0.9.1)
6
6
  rainbow (~> 3.0)
7
7
  terminal-table (~> 1.8)
data/README.md CHANGED
@@ -34,6 +34,10 @@ You can run `kovid --help` to see the full list of available commands.
34
34
  You can fetch aggregated data on Africa:
35
35
  * `kovid africa`.
36
36
 
37
+ 🏰🏰🏰
38
+
39
+ You can fetch aggregated Europe (all 44 countries combined) data:
40
+ * `kovid europe`.
37
41
 
38
42
  πŸ‡ͺπŸ‡ΊπŸ‡ͺπŸ‡ΊπŸ‡ͺπŸ‡Ί
39
43
 
@@ -47,7 +51,6 @@ You can fetch US state-specific data:
47
51
 
48
52
  ##### πŸ”œ Upcoming Fetch Features πŸ‘·β€β™€οΈ
49
53
 
50
- * `kovid europe` Aggrated stats on Europe
51
54
  * `kovid asia` Aggrated stats on Asia
52
55
  * `kovid south_america` Aggrated stats on South America
53
56
  ___
@@ -13,6 +13,9 @@ module Kovid
13
13
  def eu_aggregate
14
14
  Kovid::Request.eu_aggregate
15
15
  end
16
+ def europe_aggregate
17
+ Kovid::Request.europe_aggregate
18
+ end
16
19
 
17
20
  def africa_aggregate
18
21
  Kovid::Request.africa_aggregate
@@ -59,6 +59,11 @@ module Kovid
59
59
  data_source
60
60
  end
61
61
 
62
+ desc 'europe', 'Returns aggregated data on Europe.'
63
+ def europe
64
+ puts Kovid.europe_aggregate
65
+ data_source
66
+ end
62
67
 
63
68
  desc 'africa', 'Returns aggregated data on Africa.'
64
69
  def africa
@@ -10,48 +10,34 @@ module Kovid
10
10
  COUNTRIES_PATH = UriBuilder.new('/countries').url
11
11
  STATES_URL = UriBuilder.new('/states').url
12
12
  EU_ISOS = %w[AT BE BG CY CZ DE DK EE ES FI FR GR HR HU IE IT LT LU LV MT NL PL PT RO SE SI SK].freeze
13
+ EUROPE_ISOS = EU_ISOS + %w[GB IS NO CH MC AD SM VA BA RS ME MK AL BY UA RU MD]
13
14
  AFRICA_ISOS = %w[DZ AO BJ BW BF BI CM CV CF TD KM CD CG CI DJ EG GQ ER SZ ET GA GM GH GN GW KE LS LR LY MG MW ML MR MU MA MZ NA NE NG RW ST SN SC SL SO ZA SS SD TZ TG TN UG ZM ZW EH].freeze
15
+
14
16
  SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
15
17
 
16
18
  class << self
17
19
  def eu_aggregate
18
- countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
19
-
20
- eu_array = countries_array.select do |hash|
21
- EU_ISOS.include?(hash['countryInfo']['iso2'])
20
+ eu_proc = proc do |data|
21
+ Kovid::Tablelize.eu_aggregate(data)
22
22
  end
23
23
 
24
- head, *tail = eu_array
25
- eu_data = head.merge(*tail) do |key, left, right|
26
- left ||= 0
27
- right ||= 0
24
+ aggregator(EU_ISOS, eu_proc)
25
+ end
28
26
 
29
- left + right unless %w[country countryInfo].include?(key)
30
- end.compact
27
+ def europe_aggregate
28
+ europe_proc = proc do |data|
29
+ Kovid::Tablelize.europe_aggregate(data)
30
+ end
31
31
 
32
- Kovid::Tablelize.eu_aggregate(eu_data)
33
- rescue JSON::ParserError
34
- puts SERVER_DOWN
32
+ aggregator(EUROPE_ISOS, europe_proc)
35
33
  end
36
34
 
37
35
  def africa_aggregate
38
- countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
39
-
40
- africa_arry = countries_array.select do |hash|
41
- AFRICA_ISOS.include?(hash['countryInfo']['iso2'])
36
+ africa_proc = proc do |data|
37
+ Kovid::Tablelize.africa_aggregate(data)
42
38
  end
43
39
 
44
- head, *tail = africa_arry
45
- africa_data = head.merge(*tail) do |key, left, right|
46
- left ||= 0
47
- right ||= 0
48
-
49
- left + right unless %w[country countryInfo].include?(key)
50
- end.compact
51
-
52
- Kovid::Tablelize.africa_aggregate(africa_data)
53
- rescue JSON::ParserError
54
- puts SERVER_DOWN
40
+ aggregator(AFRICA_ISOS, africa_proc)
55
41
  end
56
42
 
57
43
  def by_country(country_name)
@@ -172,6 +158,27 @@ module Kovid
172
158
 
173
159
  states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
174
160
  end
161
+
162
+ def aggregator(isos, meth)
163
+ countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
164
+
165
+ country_array = countries_array.select do |hash|
166
+ isos.include?(hash['countryInfo']['iso2'])
167
+ end
168
+
169
+ head, *tail = country_array
170
+ data = head.merge(*tail) do |key, left, right|
171
+ left ||= 0
172
+ right ||= 0
173
+
174
+ left + right unless %w[country countryInfo].include?(key)
175
+ end.compact
176
+
177
+ # Kovid::Tablelize.eu_aggregate(data)
178
+ meth.call(data)
179
+ rescue JSON::ParserError
180
+ puts SERVER_DOWN
181
+ end
175
182
  end
176
183
  end
177
184
  end
@@ -271,41 +271,15 @@ module Kovid
271
271
  end
272
272
 
273
273
  def eu_aggregate(eu_data)
274
- rows = []
275
- rows << [
276
- comma_delimit(eu_data['cases']),
277
- check_if_positve(eu_data['todayCases']),
278
- comma_delimit(eu_data['deaths']),
279
- check_if_positve(eu_data['todayDeaths']),
280
- comma_delimit(eu_data['recovered']),
281
- comma_delimit(eu_data['active']),
282
- comma_delimit(eu_data['critical'])
283
- ]
274
+ aggregated_table(eu_data, 'The EU', Kovid::Request::EU_ISOS, 'πŸ‡ͺπŸ‡Ί')
275
+ end
284
276
 
285
- Terminal::Table.new(
286
- title: 'πŸ‡ͺπŸ‡Ί' + 8203.chr(Encoding::UTF_8) + ' Aggregated EU (27 States) Data'.upcase,
287
- headings: CONTINENTAL_AGGREGATE_HEADINGS,
288
- rows: rows
289
- )
277
+ def europe_aggregate(europe_data)
278
+ aggregated_table(europe_data, 'Europe', Kovid::Request::EUROPE_ISOS, "🏰")
290
279
  end
291
280
 
292
281
  def africa_aggregate(africa_data)
293
- rows = []
294
- rows << [
295
- comma_delimit(africa_data['cases']),
296
- check_if_positve(africa_data['todayCases']),
297
- comma_delimit(africa_data['deaths']),
298
- check_if_positve(africa_data['todayDeaths']),
299
- comma_delimit(africa_data['recovered']),
300
- comma_delimit(africa_data['active']),
301
- comma_delimit(africa_data['critical'])
302
- ]
303
-
304
- Terminal::Table.new(
305
- title: 'Aggregated Data of Africa (55 States)'.upcase,
306
- headings: CONTINENTAL_AGGREGATE_HEADINGS,
307
- rows: rows
308
- )
282
+ aggregated_table(africa_data, 'Africa', Kovid::Request::AFRICA_ISOS, '🌍')
309
283
  end
310
284
 
311
285
  private
@@ -335,6 +309,31 @@ module Kovid
335
309
  rows = [[msg]]
336
310
  puts Terminal::Table.new title: 'SCALE', rows: rows
337
311
  end
312
+
313
+ def aggregated_table(collated_data, continent, iso, emoji)
314
+ title = if emoji.codepoints.size > 1
315
+ emoji + 8203.chr(Encoding::UTF_8) + " Aggregated Data of #{continent} (#{iso.size} States)".upcase
316
+ else
317
+ emoji + " Aggregated Data of #{continent} (#{iso.size} States)".upcase
318
+ end
319
+
320
+ rows = []
321
+ rows << [
322
+ comma_delimit(collated_data['cases']),
323
+ check_if_positve(collated_data['todayCases']),
324
+ comma_delimit(collated_data['deaths']),
325
+ check_if_positve(collated_data['todayDeaths']),
326
+ comma_delimit(collated_data['recovered']),
327
+ comma_delimit(collated_data['active']),
328
+ comma_delimit(collated_data['critical'])
329
+ ]
330
+
331
+ Terminal::Table.new(
332
+ title: title,
333
+ headings: CONTINENTAL_AGGREGATE_HEADINGS,
334
+ rows: rows
335
+ )
336
+ end
338
337
  end
339
338
  end
340
339
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.4.5'
4
+ VERSION = '0.4.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kovid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Hayford