kovid 0.4.11 β†’ 0.5.0

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: 3d27663428f061e75f69ae9d3110bae2a421550683a98757b7500b2813cb8f65
4
- data.tar.gz: 27c9ce9b8697d468edf40cb869ecba3a85768559626bcdad685707938a0e00a7
3
+ metadata.gz: e6ef7ae7570fd2c03a726d7874bfaca26c60c2e3f218e362bbb43c7db52fe609
4
+ data.tar.gz: 3365f9615ffb792ca0ad959ec251240943e3ae73f1cb71f3b8c847f1e25f2dba
5
5
  SHA512:
6
- metadata.gz: f5d11f328ec94cce0e3a13cad8668bb3a6a71a19140d4f8a1ea87d981922195370a4bd8e52562ae3a67cb16903a8f46ef70afbf218bf2a7d20180a348e0580d7
7
- data.tar.gz: 29f3629879ea3aed120c91ae16eb1366f853ef604398f17fd05e59fb4521dcd0d77aeae5f28db4d09e96b9418be93f7a0d3aa20d7bfcd391d1788565e13f81f1
6
+ metadata.gz: 9f51fca509d8e54dc62b5cf971e4900c3f97a026d9c8b6a3237c934ad340cf9db63ff0f41e90b5c9bee49be90b35f1b2a9d63bb4e83f9b1bcf2249bd18da73df
7
+ data.tar.gz: 6faafaa2c3ddf39bfe1c3bc938cdfb93e313b5b998eacf8fd95278a44ecbc5148d4712e4601bae66bbabb7a4fa76760f6014ea6be42506b21911eff76b756e26
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.4.10)
4
+ kovid (0.4.11)
5
5
  ascii_charts (~> 0.9.1)
6
6
  rainbow (~> 3.0)
7
7
  terminal-table (~> 1.8)
data/README.md CHANGED
@@ -26,8 +26,8 @@ You can run `kovid --help` to see the full list of available commands.
26
26
  #### Commands Overview
27
27
 
28
28
  😷 **Fetching**
29
- * `kovid check COUNTRY` OR `kovid country COUNTRY`.
30
- * `kovid check COUNTRY -f` OR `kovid check COUNTRY --full`.
29
+ * `kovid check COUNTRY` aliased as `kovid country COUNTRY`.
30
+ * `kovid check COUNTRY -f` aliased as `kovid country COUNTRY --full`.
31
31
 
32
32
  You can get continental information with the following commands:
33
33
 
@@ -52,8 +52,10 @@ Where `FOO` and `BAR` are different countries.
52
52
 
53
53
  You can compare as many countries as you want; `kovid compare FOO BAR BAZ` OR `kovid compare FOO BAR BAZ -f`
54
54
 
55
- ##### πŸ”œ Upcoming Compare Features πŸ‘·β€β™‚οΈ
56
- * `kovid compare US_STATE1 US_STATE ...` Side-by-side stats on two/more US states.
55
+ πŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡Έ
56
+
57
+ You can compare US states with:
58
+ * `kovid compare STATE STATE` Example: `kovid states illinois "new york" california`
57
59
  ___
58
60
  😷 **History**
59
61
  * `kovid history COUNTRY` (full history).
data/lib/kovid/cli.rb CHANGED
@@ -41,6 +41,11 @@ module Kovid
41
41
  data_source
42
42
  end
43
43
 
44
+ desc 'states STATE STATE', 'Returns full comparison table for the given states. Accepts multiple states.'
45
+ def states(*states)
46
+ puts Kovid.states(states)
47
+ end
48
+
44
49
  desc 'world', 'Returns total number of cases, deaths and recoveries.'
45
50
  def world
46
51
  puts Kovid.cases
data/lib/kovid/request.rb CHANGED
@@ -9,14 +9,15 @@ module Kovid
9
9
  class Request
10
10
  COUNTRIES_PATH = UriBuilder.new('/countries').url
11
11
  STATES_URL = UriBuilder.new('/states').url
12
+
13
+ SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
14
+
12
15
  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
16
  EUROPE_ISOS = EU_ISOS + %w[GB IS NO CH MC AD SM VA BA RS ME MK AL BY UA RU MD]
14
17
  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
18
  SOUTH_AMERICA_ISOS = ['AR' 'BO', 'BV', 'BR', 'CL', 'CO', 'EC', 'FK', 'GF', 'GY', 'PY', 'PE', 'GS', 'SR', 'UY', 'VE'].freeze
16
19
  ASIA_ISOS = %w[AE AF AM AZ BD BH BN BT CC CN CX GE HK ID IL IN IQ IR JO JP KG KH KP KR KW KZ LA LB LK MM MN MO MY NP OM PH PK PS QA SA SG SY TH TJ TL TM TR TW UZ VN YE].freeze
17
20
 
18
- SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
19
-
20
21
  class << self
21
22
  def eu_aggregate
22
23
  eu_proc = proc do |data|
@@ -161,10 +162,11 @@ module Kovid
161
162
  end
162
163
 
163
164
  def fetch_states(list)
164
- array = []
165
+ states_json = JSON.parse(Typhoeus.get(STATES_URL, cache_ttl: 900).response_body)
166
+ states_array = []
165
167
 
166
- list.each do |state|
167
- array << JSON.parse(Typhoeus.get(COUNTRIES_PATH + "/#{state}", cache_ttl: 900).response_body)
168
+ states_json.select do |state|
169
+ states_array << state if list.include?(state['state'].downcase)
168
170
  end
169
171
  end
170
172
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  require 'terminal-table'
4
4
  require 'date'
5
- require_relative 'painter'
6
5
  require 'ascii_charts'
6
+ require_relative 'painter'
7
7
 
8
8
  module Kovid
9
9
  class Tablelize
@@ -58,11 +58,29 @@ module Kovid
58
58
  'Recovered'.paint_green
59
59
  ].freeze
60
60
 
61
+ FULL_COUNTRY_TABLE_HEADINGS = [
62
+ 'Cases'.paint_white,
63
+ 'Deaths'.paint_red,
64
+ 'Recovered'.paint_green,
65
+ 'Cases Today'.paint_white,
66
+ 'Deaths Today'.paint_red,
67
+ 'Critical'.paint_yellow,
68
+ 'Cases/Million'.paint_white
69
+ ].freeze
70
+
71
+ COMPARE_STATES_HEADINGS = [
72
+ 'State'.paint_white,
73
+ 'Cases'.paint_white,
74
+ 'Cases Today'.paint_white,
75
+ 'Deaths'.paint_red,
76
+ 'Deaths Today'.paint_red,
77
+ 'Active'.paint_yellow
78
+ ].freeze
79
+
61
80
  FOOTER_LINE = ['------------', '------------', '------------'].freeze
62
81
  COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
63
82
 
64
83
  def country_table(data)
65
- headings = CASES_DEATHS_RECOVERED_CTODAY_DTODAY
66
84
  rows = [
67
85
  [
68
86
  comma_delimit(data['cases']),
@@ -73,24 +91,18 @@ module Kovid
73
91
  ]
74
92
  ]
75
93
 
76
- if iso = data['countryInfo']['iso2']
77
- Terminal::Table.new(title: "#{country_emoji(iso)} #{data['country'].upcase}", headings: headings, rows: rows)
94
+ if (iso = data['countryInfo']['iso2'])
95
+ Terminal::Table.new(title: "#{country_emoji(iso)} #{data['country'].upcase}",
96
+ headings: CASES_DEATHS_RECOVERED_CTODAY_DTODAY,
97
+ rows: rows)
78
98
  else
79
- Terminal::Table.new(title: data['country'].upcase, headings: headings, rows: rows)
99
+ Terminal::Table.new(title: data['country'].upcase,
100
+ headings: CASES_DEATHS_RECOVERED_CTODAY_DTODAY,
101
+ rows: rows)
80
102
  end
81
103
  end
82
104
 
83
105
  def full_country_table(data)
84
- headings = [
85
- 'Cases'.paint_white,
86
- 'Deaths'.paint_red,
87
- 'Recovered'.paint_green,
88
- 'Cases Today'.paint_white,
89
- 'Deaths Today'.paint_red,
90
- 'Critical'.paint_yellow,
91
- 'Cases/Million'.paint_white
92
- ]
93
-
94
106
  rows = []
95
107
  rows << [
96
108
  comma_delimit(data['cases']),
@@ -104,14 +116,13 @@ module Kovid
104
116
 
105
117
  if iso = data['countryInfo']['iso2']
106
118
  Terminal::Table.new(title: "#{country_emoji(iso)} #{data['country'].upcase}",
107
- headings: headings,
119
+ headings: FULL_COUNTRY_TABLE_HEADINGS,
108
120
  rows: rows)
109
121
  else
110
122
  Terminal::Table.new(title: data['country'].upcase,
111
- headings: headings,
123
+ headings: FULL_COUNTRY_TABLE_HEADINGS,
112
124
  rows: rows)
113
125
  end
114
- # TODO: Rafactor this
115
126
  end
116
127
 
117
128
  def full_state_table(state)
@@ -141,7 +152,7 @@ module Kovid
141
152
  comma_delimit(country['recovered'])
142
153
  ]
143
154
 
144
- rows << if iso = country['countryInfo']['iso2']
155
+ rows << if (iso = country['countryInfo']['iso2'])
145
156
  base_rows.unshift("#{country_emoji(iso)} #{country['country'].upcase}")
146
157
  else
147
158
  base_rows.unshift(country['country'].upcase.to_s)
@@ -168,6 +179,21 @@ module Kovid
168
179
  Terminal::Table.new(headings: COMPARE_COUNTRY_TABLE_FULL, rows: rows)
169
180
  end
170
181
 
182
+ def compare_us_states(data)
183
+ rows = data.map do |state|
184
+ [
185
+ state.fetch('state').upcase,
186
+ comma_delimit(state.fetch('cases')),
187
+ check_if_positve(state['todayCases']),
188
+ comma_delimit(state['deaths']),
189
+ check_if_positve(state['todayDeaths']),
190
+ comma_delimit(state.fetch('active'))
191
+ ]
192
+ end
193
+
194
+ Terminal::Table.new(headings: COMPARE_STATES_HEADINGS, rows: rows)
195
+ end
196
+
171
197
  def cases(cases)
172
198
  headings = CASES_DEATHS_RECOVERED
173
199
  rows = [
@@ -273,6 +299,8 @@ module Kovid
273
299
 
274
300
  scale("Scale on Y: #{y_interval}:#{(y_interval / last_two_y.last.to_f * positive_cases_figures.last).round(2) / y_interval}")
275
301
 
302
+ puts 'Experimental feature, please report issues.'
303
+
276
304
  AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).draw
277
305
  end
278
306
  end
@@ -286,7 +314,8 @@ module Kovid
286
314
  end
287
315
 
288
316
  def africa_aggregate(africa_data)
289
- aggregated_table(africa_data, 'Africa', Kovid::Request::AFRICA_ISOS, '🌍')
317
+ aggregated_table(africa_data, 'Africa',
318
+ Kovid::Request::AFRICA_ISOS, '🌍')
290
319
  end
291
320
 
292
321
  def south_america_aggregate(south_america_data)
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.4.11'
4
+ VERSION = '0.5.0'
5
5
  end
data/lib/kovid.rb CHANGED
@@ -42,7 +42,7 @@ module Kovid
42
42
  Kovid::Request.state(state)
43
43
  end
44
44
 
45
- def states(*states)
45
+ def states(states)
46
46
  Kovid::Request.states(states)
47
47
  end
48
48
 
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.4.11
4
+ version: 0.5.0
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-29 00:00:00.000000000 Z
11
+ date: 2020-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor