kovid 0.5.2 → 0.5.3

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: 9e5b928695ed30eef22a377df09509cb817b0db67723b452934d4d9d7ef928e9
4
- data.tar.gz: 550215c5eaa911ac354bfe5d14027ce272061b70e7c364b92c8a846c632298d7
3
+ metadata.gz: b7ae0b899f1e91e81fde1171491b4dd933eb022f1936f96686ca3ead29f4fca1
4
+ data.tar.gz: 145b553fca0604fc0c055f7402df0f4e5040a10153ae77a73d0dee0e4c3b4888
5
5
  SHA512:
6
- metadata.gz: 587bb5f88a9e2c5af493f4d1e6ad49e77bd580f1cbf72f629a42890d3a218b5406bd4a4123d401a5f8a1694b70f717dccf03851dfaaff7014121adcd35a9f088
7
- data.tar.gz: 95542b8fe35f9e06aeeffab5233d7de059e96a14fb95283fa4081459c56b5fd3de84b98e18f77d0de5de539d4a84e23fd4900e34f5701552301b5c2ddd53434b
6
+ metadata.gz: f4810dd236e8fce6ac8866349b881c30b8627bfc77e59d259603d157d1bf26a582d27a305df350aef259231fd48cde98a5d43dfdc20de990dacfa75283f53408
7
+ data.tar.gz: 6d7892a076c769e90ed0ead3fddfe4d639c2d3cd41d05bc038094d864c4cd97268cda3cd0bf388d17bf50bf595bce80983a8d54e93d7fed8827e1df83348f8e3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.5.0)
4
+ kovid (0.5.2)
5
5
  ascii_charts (~> 0.9.1)
6
6
  rainbow (~> 3.0)
7
7
  terminal-table (~> 1.8)
data/README.md CHANGED
@@ -43,6 +43,12 @@ You can get continental information with the following commands:
43
43
  You can fetch US state-specific data:
44
44
  * `kovid state STATE` OR `kovid state "STATE NAME"`.
45
45
 
46
+ Provinces
47
+
48
+ You can fetch province specific data:
49
+
50
+ * `kovid province PROVINCE` or `kovid province "PROVINCE NAME"`.
51
+
46
52
  ___
47
53
  😷 **Comparing**
48
54
  * `kovid compare FOO BAR` (sorts by cases DESC).
@@ -56,6 +62,9 @@ You can compare as many countries as you want; `kovid compare FOO BAR BAZ` OR `k
56
62
 
57
63
  You can compare US states with:
58
64
  * `kovid compare STATE STATE` Example: `kovid states illinois "new york" california`
65
+
66
+ You can compare provicnes with:
67
+ * `kovid provinces PROVINCE PROVINCE` Example: `kovid provinces ontario manitoba`
59
68
  ___
60
69
  😷 **History**
61
70
  * `kovid history COUNTRY` (full history).
data/lib/kovid.rb CHANGED
@@ -38,6 +38,14 @@ module Kovid
38
38
  Kovid::Request.by_country_full(name)
39
39
  end
40
40
 
41
+ def province(name)
42
+ Kovid::Request.province(name)
43
+ end
44
+
45
+ def provinces(names)
46
+ Kovid::Request.provinces(names)
47
+ end
48
+
41
49
  def state(state)
42
50
  Kovid::Request.state(state)
43
51
  end
data/lib/kovid/cli.rb CHANGED
@@ -11,6 +11,18 @@ module Kovid
11
11
  true
12
12
  end
13
13
 
14
+ desc 'province PROVINCE or province "PROVINCE NAME"', 'Returns reported data on provided province. eg "kovid check "new brunswick".'
15
+ method_option :full, aliases: '-p'
16
+ def province(name)
17
+ puts Kovid.province(name)
18
+ data_source
19
+ end
20
+
21
+ desc 'provinces PROVINCE PROVINCE', 'Returns full comparison table for the given provinces. Accepts multiple provinces.'
22
+ def provinces(*names)
23
+ puts Kovid.provinces(names)
24
+ end
25
+
14
26
  desc 'check COUNTRY or check "COUNTRY NAME"', 'Returns reported data on provided country. eg: "kovid check "hong kong".'
15
27
  method_option :full, aliases: '-f'
16
28
  def check(name)
data/lib/kovid/request.rb CHANGED
@@ -9,6 +9,7 @@ module Kovid
9
9
  class Request
10
10
  COUNTRIES_PATH = UriBuilder.new('/countries').url
11
11
  STATES_URL = UriBuilder.new('/states').url
12
+ JHUCSSE_URL = UriBuilder.new('/v2/jhucsse').url
12
13
 
13
14
  SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
14
15
 
@@ -83,6 +84,21 @@ module Kovid
83
84
  puts SERVER_DOWN
84
85
  end
85
86
 
87
+ def province(province)
88
+ response = fetch_province(province)
89
+ if response.nil?
90
+ not_found(province)
91
+ else
92
+ Kovid::Tablelize.full_province_table(response)
93
+ end
94
+ end
95
+
96
+ def provinces(names)
97
+ array = fetch_provinces(names)
98
+
99
+ Kovid::Tablelize.compare_provinces(array)
100
+ end
101
+
86
102
  def state(state)
87
103
  response = fetch_state(state)
88
104
  if response.nil?
@@ -176,6 +192,21 @@ module Kovid
176
192
  JSON.parse(Typhoeus.get(country_url, cache_ttl: 900).response_body)
177
193
  end
178
194
 
195
+ def fetch_jhucsse
196
+ JSON.parse(Typhoeus.get(JHUCSSE_URL, cache_ttl: 900).response_body)
197
+ end
198
+
199
+ def fetch_province(province)
200
+ response = fetch_jhucsse
201
+ response.select { |datum| datum['province'] == capitalize_words(province) }.first
202
+ end
203
+
204
+ def fetch_provinces(provinces)
205
+ provinces.map!(&method(:capitalize_words))
206
+ response = fetch_jhucsse
207
+ response.select { |datum| provinces.include? datum['province'] }
208
+ end
209
+
179
210
  def fetch_state(state)
180
211
  states_array = JSON.parse(Typhoeus.get(STATES_URL, cache_ttl: 900).response_body)
181
212
 
@@ -189,16 +220,6 @@ module Kovid
189
220
  isos.include?(hash['countryInfo']['iso2'])
190
221
  end
191
222
 
192
- # You can't do this for Ruby veresion < 2.6.0
193
- # #merge behaviour was changed in Ruby 2.6.0
194
- # head, *tail = country_array
195
- # data = head.merge(*tail) do |key, left, right|
196
- # left ||= 0
197
- # right ||= 0
198
-
199
- # left + right unless %w[country countryInfo].include?(key)
200
- # end.compact
201
-
202
223
  data = country_array.inject do |base, other|
203
224
  base.merge(other) do |key, left, right|
204
225
  left ||= 0
@@ -78,6 +78,13 @@ module Kovid
78
78
  'Active'.paint_yellow
79
79
  ].freeze
80
80
 
81
+ COMPARE_PROVINCES_HEADINGS = [
82
+ 'Province'.paint_white,
83
+ 'Confirmed'.paint_white,
84
+ 'Deaths'.paint_red,
85
+ 'Recovered'.paint_green
86
+ ].freeze
87
+
81
88
  FOOTER_LINE = ['------------', '------------', '------------', '------------'].freeze
82
89
  COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
83
90
 
@@ -126,6 +133,18 @@ module Kovid
126
133
  end
127
134
  end
128
135
 
136
+ def full_province_table(province)
137
+ headings = [
138
+ 'Confirmed'.paint_white,
139
+ 'Deaths'.paint_red,
140
+ 'Recovered'.paint_green
141
+ ]
142
+ rows = []
143
+ rows << [province['stats']['confirmed'], province['stats']['deaths'], province['stats']['recovered']]
144
+
145
+ Terminal::Table.new(title: province['province'].upcase, headings: headings, rows: rows)
146
+ end
147
+
129
148
  def full_state_table(state)
130
149
  headings = [
131
150
  'Cases'.paint_white,
@@ -195,6 +214,19 @@ module Kovid
195
214
  Terminal::Table.new(headings: COMPARE_STATES_HEADINGS, rows: rows)
196
215
  end
197
216
 
217
+ def compare_provinces(data)
218
+ rows = data.map do |province|
219
+ [
220
+ province['province'].upcase,
221
+ province['stats']['confirmed'],
222
+ province['stats']['deaths'],
223
+ province['stats']['recovered']
224
+ ]
225
+ end
226
+
227
+ Terminal::Table.new(headings: COMPARE_PROVINCES_HEADINGS, rows: rows)
228
+ end
229
+
198
230
  def cases(cases)
199
231
  headings = CASES_DEATHS_RECOVERED
200
232
  rows = [
data/lib/kovid/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.5.2'
4
+ VERSION = '0.5.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kovid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Hayford
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-30 00:00:00.000000000 Z
11
+ date: 2020-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor