kovid 0.6.2 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +59 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +18 -1
- data/README.md +3 -1
- data/Rakefile +1 -0
- data/kovid.gemspec +9 -4
- data/lib/kovid.rb +0 -2
- data/lib/kovid/aggregators.rb +28 -0
- data/lib/kovid/cache.rb +0 -1
- data/lib/kovid/cli.rb +33 -33
- data/lib/kovid/constants.rb +112 -0
- data/lib/kovid/helpers.rb +22 -0
- data/lib/kovid/historians.rb +108 -0
- data/lib/kovid/painter.rb +0 -1
- data/lib/kovid/request.rb +62 -28
- data/lib/kovid/tablelize.rb +118 -346
- data/lib/kovid/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a77d1ad2686877dfe810f0df3cbc817b46c287f2a6025ce999108213ad0e54c8
|
4
|
+
data.tar.gz: 888dab7db56dc55241512e24bef98fb9f9117abd9e09790a19894630d691e0c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6394d6904a073fef5c4fa1d6429c3789a84dfc329a519346dd90e53b082b22284405a044a13c984cf231f7cdd02fb790c49450c47c1d6c0fecb124fbc67783e5
|
7
|
+
data.tar.gz: 7c45571d9683f723068c6d17a97427348c5d3f8ed64db76e2bd71db72af322f3611bd0d66af8dc3732d4a251f1253d2ea0d49c0db34f8c905739f7cc7dd885cc
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2020-04-07 20:38:28 -0300 using RuboCop version 0.67.2.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 54
|
12
|
+
Exclude:
|
13
|
+
- 'lib/kovid/historians.rb'
|
14
|
+
|
15
|
+
# Offense count: 2
|
16
|
+
Metrics/BlockLength:
|
17
|
+
Exclude:
|
18
|
+
- 'kovid.gemspec'
|
19
|
+
- 'spec/kovid_spec.rb'
|
20
|
+
|
21
|
+
# Offense count: 3
|
22
|
+
# Configuration parameters: CountComments.
|
23
|
+
Metrics/ClassLength:
|
24
|
+
Max: 220
|
25
|
+
Exclude:
|
26
|
+
- 'lib/kovid/cli.rb'
|
27
|
+
- 'lib/kovid/request.rb'
|
28
|
+
- 'lib/kovid/tablelize.rb'
|
29
|
+
|
30
|
+
# Offense count: 2
|
31
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
32
|
+
Metrics/MethodLength:
|
33
|
+
Max: 44
|
34
|
+
Exclude:
|
35
|
+
- 'lib/kovid/historians.rb'
|
36
|
+
|
37
|
+
# Offense count: 1
|
38
|
+
Metrics/PerceivedComplexity:
|
39
|
+
Max: 8
|
40
|
+
Exclude:
|
41
|
+
- 'lib/kovid/historians.rb'
|
42
|
+
|
43
|
+
# Offense count: 1
|
44
|
+
Style/CaseEquality:
|
45
|
+
Exclude:
|
46
|
+
- 'lib/kovid/request.rb'
|
47
|
+
|
48
|
+
Style/Documentation:
|
49
|
+
Exclude:
|
50
|
+
- 'spec/**/*'
|
51
|
+
- 'test/**/*'
|
52
|
+
- 'lib/kovid.rb'
|
53
|
+
- 'lib/kovid/helpers.rb'
|
54
|
+
|
55
|
+
# Offense count: 5
|
56
|
+
Style/MultilineBlockChain:
|
57
|
+
Exclude:
|
58
|
+
- 'lib/kovid/historians.rb'
|
59
|
+
- 'lib/kovid/request.rb'
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kovid (0.6.
|
4
|
+
kovid (0.6.6)
|
5
5
|
ascii_charts (~> 0.9.1)
|
6
6
|
rainbow (~> 3.0)
|
7
7
|
terminal-table (~> 1.8)
|
@@ -11,12 +11,24 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
+
activesupport (6.0.2.2)
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
i18n (>= 0.7, < 2)
|
17
|
+
minitest (~> 5.1)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
zeitwerk (~> 2.2)
|
14
20
|
ascii_charts (0.9.1)
|
21
|
+
carmen (1.1.3)
|
22
|
+
activesupport (>= 3.0.0)
|
23
|
+
concurrent-ruby (1.1.6)
|
15
24
|
diff-lcs (1.3)
|
16
25
|
docile (1.3.2)
|
17
26
|
ethon (0.12.0)
|
18
27
|
ffi (>= 1.3.0)
|
19
28
|
ffi (1.12.2)
|
29
|
+
i18n (1.8.2)
|
30
|
+
concurrent-ruby (~> 1.0)
|
31
|
+
minitest (5.14.0)
|
20
32
|
rainbow (3.0.0)
|
21
33
|
rake (12.3.3)
|
22
34
|
rspec (3.9.0)
|
@@ -39,14 +51,19 @@ GEM
|
|
39
51
|
terminal-table (1.8.0)
|
40
52
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
41
53
|
thor (1.0.1)
|
54
|
+
thread_safe (0.3.6)
|
42
55
|
typhoeus (1.3.1)
|
43
56
|
ethon (>= 0.9.0)
|
57
|
+
tzinfo (1.2.7)
|
58
|
+
thread_safe (~> 0.1)
|
44
59
|
unicode-display_width (1.7.0)
|
60
|
+
zeitwerk (2.3.0)
|
45
61
|
|
46
62
|
PLATFORMS
|
47
63
|
ruby
|
48
64
|
|
49
65
|
DEPENDENCIES
|
66
|
+
carmen (~> 1.1.3)
|
50
67
|
kovid!
|
51
68
|
rake (~> 12.0)
|
52
69
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -46,6 +46,8 @@ You can fetch US state-specific data:
|
|
46
46
|
* `kovid state STATE` OR `kovid state "STATE NAME"`.
|
47
47
|
* `kovid states --all` or `kovid states -a` for data on all US states.
|
48
48
|
|
49
|
+
You can also use USPS abbreviations. Example: `kovid state me`
|
50
|
+
|
49
51
|
Provinces
|
50
52
|
|
51
53
|
You can fetch province specific data:
|
@@ -64,7 +66,7 @@ You can compare as many countries as you want; `kovid compare FOO BAR BAZ` OR `k
|
|
64
66
|
🇺🇸🇺🇸🇺🇸
|
65
67
|
|
66
68
|
You can compare US states with:
|
67
|
-
* `kovid states STATE STATE` Example: `kovid states illinois "new york" california`
|
69
|
+
* `kovid states STATE STATE` Example: `kovid states illinois "new york" california` OR `kovid states il ny ca`
|
68
70
|
|
69
71
|
You can compare provicnes with:
|
70
72
|
* `kovid provinces PROVINCE PROVINCE` Example: `kovid provinces ontario manitoba`
|
data/Rakefile
CHANGED
data/kovid.gemspec
CHANGED
@@ -8,8 +8,10 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['Emmanuel Hayford']
|
9
9
|
spec.email = ['siawmensah@gmail.com']
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
summary = 'A CLI to fetch and compare the 2019 ' \
|
12
|
+
'coronavirus pandemic statistics.'
|
13
|
+
spec.summary = summary
|
14
|
+
spec.description = summary
|
13
15
|
spec.homepage = 'https://github.com/siaw23/kovid'
|
14
16
|
spec.license = 'MIT'
|
15
17
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
@@ -29,9 +31,12 @@ Gem::Specification.new do |spec|
|
|
29
31
|
spec.add_development_dependency 'simplecov', '~> 0.18'
|
30
32
|
|
31
33
|
# Specify which files should be added to the gem when it is released.
|
32
|
-
# The `git ls-files -z` loads the files in the RubyGem
|
34
|
+
# The `git ls-files -z` loads the files in the RubyGem
|
35
|
+
# that have been added into git.
|
33
36
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
34
|
-
`git ls-files -z`.split("\x0").reject
|
37
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
38
|
+
f.match(%r{^(test|spec|features)/})
|
39
|
+
end
|
35
40
|
end
|
36
41
|
spec.bindir = 'exe'
|
37
42
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
data/lib/kovid.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kovid
|
4
|
+
module Aggregators
|
5
|
+
def eu_aggregate(eu_data)
|
6
|
+
aggregated_table(eu_data, 'The EU', Kovid::Request::EU_ISOS, '🇪🇺')
|
7
|
+
end
|
8
|
+
|
9
|
+
def europe_aggregate(europe_data)
|
10
|
+
aggregated_table(europe_data, 'Europe', Kovid::Request::EUROPE_ISOS, '🏰')
|
11
|
+
end
|
12
|
+
|
13
|
+
def africa_aggregate(africa_data)
|
14
|
+
aggregated_table(africa_data, 'Africa',
|
15
|
+
Kovid::Request::AFRICA_ISOS, '🌍')
|
16
|
+
end
|
17
|
+
|
18
|
+
def south_america_aggregate(south_america_data)
|
19
|
+
aggregated_table(south_america_data,
|
20
|
+
'South America',
|
21
|
+
Kovid::Request::SOUTH_AMERICA_ISOS, '🌎')
|
22
|
+
end
|
23
|
+
|
24
|
+
def asia_aggregate(asia_data)
|
25
|
+
aggregated_table(asia_data, 'Asia', Kovid::Request::ASIA_ISOS, '🌏')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/kovid/cache.rb
CHANGED
data/lib/kovid/cli.rb
CHANGED
@@ -5,37 +5,47 @@ require 'kovid'
|
|
5
5
|
|
6
6
|
module Kovid
|
7
7
|
class CLI < Thor
|
8
|
-
FULL_FLAG = %w[-f --full].freeze
|
9
|
-
|
10
8
|
def self.exit_on_failure?
|
11
9
|
true
|
12
10
|
end
|
13
11
|
|
14
|
-
desc 'province PROVINCE or province "PROVINCE NAME"',
|
12
|
+
desc 'province PROVINCE or province "PROVINCE NAME"',
|
13
|
+
'Returns reported data on provided province. ' \
|
14
|
+
'eg "kovid check "new brunswick".'
|
15
15
|
method_option :full, aliases: '-p'
|
16
16
|
def province(name)
|
17
17
|
puts Kovid.province(name)
|
18
18
|
data_source
|
19
19
|
end
|
20
20
|
|
21
|
-
desc 'provinces PROVINCE PROVINCE',
|
21
|
+
desc 'provinces PROVINCE PROVINCE',
|
22
|
+
'Returns full comparison table for the given provinces. ' \
|
23
|
+
'Accepts multiple provinces.'
|
22
24
|
def provinces(*names)
|
23
25
|
puts Kovid.provinces(names)
|
24
26
|
data_source
|
25
27
|
end
|
26
28
|
|
27
|
-
desc 'check COUNTRY or check "COUNTRY NAME"',
|
29
|
+
desc 'check COUNTRY or check "COUNTRY NAME"',
|
30
|
+
'Returns reported data on provided country. ' \
|
31
|
+
'eg: "kovid check "hong kong".'
|
28
32
|
method_option :full, aliases: '-f'
|
29
|
-
def check(name)
|
30
|
-
|
33
|
+
def check(*name)
|
34
|
+
if name.size == 1
|
35
|
+
fetch_country_stats(name.pop)
|
36
|
+
elsif options[:full]
|
37
|
+
puts Kovid.country_comparison_full(name)
|
38
|
+
else
|
39
|
+
puts Kovid.country_comparison(name)
|
40
|
+
end
|
31
41
|
data_source
|
32
42
|
end
|
43
|
+
map country: :check
|
33
44
|
|
34
|
-
desc '
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
data_source
|
45
|
+
desc 'compare COUNTRY COUNTRY', 'Deprecated. Will be removed in v7.0.0'
|
46
|
+
def compare(*_name)
|
47
|
+
Kovid.info_table("#compare is deprecated and will be removed in v7.0.0. \
|
48
|
+
\nPlease do `kovid check COUNTRY COUNTRY ...` instead.")
|
39
49
|
end
|
40
50
|
|
41
51
|
desc 'state STATE', 'Return reported data on provided state.'
|
@@ -44,29 +54,18 @@ module Kovid
|
|
44
54
|
data_source
|
45
55
|
end
|
46
56
|
|
47
|
-
desc '
|
48
|
-
|
49
|
-
|
50
|
-
|
57
|
+
desc 'states STATE STATE or states --all',
|
58
|
+
'Returns full comparison table for the given states. ' \
|
59
|
+
'Accepts multiple states.'
|
60
|
+
method_option :all, aliases: '-a'
|
61
|
+
def states(*states)
|
62
|
+
if options[:all]
|
63
|
+
puts Kovid.all_us_states
|
51
64
|
else
|
52
|
-
|
65
|
+
downcased_states = states.map(&:downcase)
|
66
|
+
puts Kovid.states(downcased_states)
|
53
67
|
end
|
54
|
-
data_source
|
55
|
-
end
|
56
|
-
|
57
|
-
desc 'states STATE STATE', 'Returns full comparison table for the given states. Accepts multiple states.'
|
58
|
-
def states(*states)
|
59
|
-
# This ensures this command is case insensitive.
|
60
|
-
downcased_states = states.map(&:downcase)
|
61
68
|
|
62
|
-
puts Kovid.states(downcased_states)
|
63
|
-
data_source
|
64
|
-
end
|
65
|
-
|
66
|
-
desc 'states -a', 'Returns full comparison table for all US states'
|
67
|
-
method_option :all, aliases: '-a'
|
68
|
-
def states
|
69
|
-
puts Kovid.all_us_states
|
70
69
|
data_source
|
71
70
|
end
|
72
71
|
|
@@ -76,7 +75,8 @@ module Kovid
|
|
76
75
|
data_source
|
77
76
|
end
|
78
77
|
|
79
|
-
desc 'history COUNTRY or history COUNTRY N',
|
78
|
+
desc 'history COUNTRY or history COUNTRY N',
|
79
|
+
'Return history of incidents of COUNTRY (in the last N days)'
|
80
80
|
def history(*params)
|
81
81
|
if params.size == 2
|
82
82
|
puts Kovid.history(params.first, params.last)
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kovid
|
4
|
+
module Constants
|
5
|
+
CASES_DEATHS_RECOVERED = [
|
6
|
+
'Cases'.paint_white,
|
7
|
+
'Deaths'.paint_red,
|
8
|
+
'Recovered'.paint_green
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
CASES_DEATHS_RECOVERED_CTODAY_DTODAY = [
|
12
|
+
'Cases'.paint_white,
|
13
|
+
'Cases Today'.paint_white,
|
14
|
+
'Deaths'.paint_red,
|
15
|
+
'Deaths Today'.paint_red,
|
16
|
+
'Recovered'.paint_green
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
DATE_CASES_DEATHS_RECOVERED = [
|
20
|
+
'Date'.paint_white,
|
21
|
+
'Cases'.paint_white,
|
22
|
+
'Deaths'.paint_red,
|
23
|
+
'Recovered'.paint_green
|
24
|
+
].freeze
|
25
|
+
|
26
|
+
CONTINENTAL_AGGREGATE_HEADINGS = [
|
27
|
+
'Cases'.paint_white,
|
28
|
+
'Cases Today'.paint_white,
|
29
|
+
'Deaths'.paint_red,
|
30
|
+
'Deaths Today'.paint_red,
|
31
|
+
'Recovered'.paint_green,
|
32
|
+
'Active'.paint_yellow,
|
33
|
+
'Critical'.paint_red
|
34
|
+
].freeze
|
35
|
+
|
36
|
+
COMPARE_COUNTRY_TABLE_FULL = [
|
37
|
+
'Country'.paint_white,
|
38
|
+
'Cases'.paint_white,
|
39
|
+
'Deaths'.paint_red,
|
40
|
+
'Recovered'.paint_green,
|
41
|
+
'Cases Today'.paint_white,
|
42
|
+
'Deaths Today'.paint_red,
|
43
|
+
'Critical'.paint_yellow,
|
44
|
+
'Cases/Million'.paint_white
|
45
|
+
].freeze
|
46
|
+
|
47
|
+
COMPARE_COUNTRIES_TABLE_HEADINGS = [
|
48
|
+
'Country'.paint_white,
|
49
|
+
'Cases'.paint_white,
|
50
|
+
'Cases Today'.paint_white,
|
51
|
+
'Deaths'.paint_red,
|
52
|
+
'Deaths Today'.paint_red,
|
53
|
+
'Recovered'.paint_green
|
54
|
+
].freeze
|
55
|
+
|
56
|
+
FULL_COUNTRY_TABLE_HEADINGS = [
|
57
|
+
'Cases'.paint_white,
|
58
|
+
'Deaths'.paint_red,
|
59
|
+
'Recovered'.paint_green,
|
60
|
+
'Cases Today'.paint_white,
|
61
|
+
'Deaths Today'.paint_red,
|
62
|
+
'Critical'.paint_yellow,
|
63
|
+
'Cases/Million'.paint_white
|
64
|
+
].freeze
|
65
|
+
|
66
|
+
FULL_PROVINCE_TABLE_HEADINGS = [
|
67
|
+
'Confirmed'.paint_white,
|
68
|
+
'Deaths'.paint_red,
|
69
|
+
'Recovered'.paint_green
|
70
|
+
].freeze
|
71
|
+
|
72
|
+
FULL_STATE_TABLE_HEADINGS = [
|
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
|
+
|
80
|
+
COMPARE_STATES_HEADINGS = [
|
81
|
+
'State'.paint_white,
|
82
|
+
'Cases'.paint_white,
|
83
|
+
'Cases Today'.paint_white,
|
84
|
+
'Deaths'.paint_red,
|
85
|
+
'Deaths Today'.paint_red,
|
86
|
+
'Active'.paint_yellow
|
87
|
+
].freeze
|
88
|
+
|
89
|
+
COMPARE_PROVINCES_HEADINGS = [
|
90
|
+
'Province'.paint_white,
|
91
|
+
'Confirmed'.paint_white,
|
92
|
+
'Deaths'.paint_red,
|
93
|
+
'Recovered'.paint_green
|
94
|
+
].freeze
|
95
|
+
|
96
|
+
FOOTER_LINE = [
|
97
|
+
'------------',
|
98
|
+
'------------',
|
99
|
+
'------------',
|
100
|
+
'------------'
|
101
|
+
].freeze
|
102
|
+
|
103
|
+
COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
|
104
|
+
|
105
|
+
RIGHT_ALIGN_COLUMNS = {
|
106
|
+
compare_country_table_full: [1, 2, 3, 4, 5, 6, 7],
|
107
|
+
compare_country_table: [1, 2, 3, 4, 5],
|
108
|
+
compare_us_states: [1, 2, 3, 4, 5],
|
109
|
+
compare_provinces: [1, 2, 3]
|
110
|
+
}.freeze
|
111
|
+
end
|
112
|
+
end
|