kovid 0.1.13 → 0.1.14

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: e574f889f4de41024c378f44dd6de7b69419dac577ff948b8758cb3aaa1abab5
4
- data.tar.gz: 5266091b77b12a389e93dcdd2925866042c2010a8a0b1af5a729cf01a1b90564
3
+ metadata.gz: af922cf964393c54e9e754d0e292e28b273d8879f6d01a26098036dfaf833028
4
+ data.tar.gz: 0f13b97fc89501ba2e874c7812dbe2b0b5f7c3a5002a8ee428ee4c645f551dac
5
5
  SHA512:
6
- metadata.gz: 51139f101e1e9094c2102f5e85e27de2a7ae02597a227fa722f7ccd7c5efaa0e59911be60486e4705b1f756785e0e6abe526ec22b2e4aabbe5940ec441a55a57
7
- data.tar.gz: a2977b5f1c17e2f478267c6a01ea1370ff5109b17e82c4ead5175a6f5d8367c0566c044563de0a315e74239d880d98030575f2bd0a336cc0a9dc2e0bd4037d5c
6
+ metadata.gz: bd75365e81cfe99be195117bc8f0c5d9babac43896f80929922bbe255f4c0052753d6fb078a71c8b7c428877297f3fd6e4997d74d17c525d2657a58112e3acc7
7
+ data.tar.gz: 580ca440ce3a0fddd3d3e3879ffa5b6617304a1036bd3cfada69e7de952bf543ea02cf7deb8af810065a883ea2256736191e8ecec8453acbc8c3a47ca58dc439
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.1.11)
4
+ kovid (0.1.13)
5
+ colorize
5
6
  terminal-table
6
7
  thor
7
8
  typhoeus
@@ -20,6 +21,7 @@ GEM
20
21
  builder (3.2.4)
21
22
  childprocess (3.0.0)
22
23
  coderay (1.1.2)
24
+ colorize (0.8.1)
23
25
  contracts (0.16.0)
24
26
  cucumber (3.1.2)
25
27
  builder (>= 2.1.2)
data/README.md CHANGED
@@ -39,7 +39,7 @@ You can run `kovid --help` to see the full list of available commands.
39
39
 
40
40
  😷 **Comparing**
41
41
  * `kovid compare ghana poland` (sorts by cases DESC)
42
- * `kovid compare ghana poland -f` OR `kovid compare ghana poland --full` (sorts by cases DESC)
42
+ * `kovid compare germany poland -f` OR `kovid compare germany poland --full` (sorts by cases DESC)
43
43
 
44
44
  You can compare as many countries as you want.
45
45
 
@@ -55,39 +55,39 @@ To fetch basic data on a country run:
55
55
 
56
56
  If the location contains spaces: `kovid check "Diamond Princess"`
57
57
 
58
- ![kovid](https://i.gyazo.com/ca57d9250c7523a921d0d7e1104716be.png "Covid data.")
58
+ ![kovid](https://i.gyazo.com/ab779c3fc838ac279bae5b9d6d10d617.png "Covid data.")
59
59
 
60
60
  For full table info on a country:
61
61
 
62
62
  `kovid check ghana -f` OR `kovid check ghana --full`
63
63
 
64
- ![kovid](https://i.gyazo.com/628f07faf8e3c1c2a0b6ab05e4a86404.png "Covid data.")
64
+ ![kovid](https://i.gyazo.com/151c8e7ac55a7b4efd27b734720863f1.png "Covid data.")
65
65
 
66
66
  To compare country stats:
67
67
 
68
- `kovid compare ghana poland`
68
+ `kovid compare germany poland`
69
69
 
70
- ![kovid](https://i.gyazo.com/a15922e13e9e6c1ba804ccf5beeb863b.png "Covid data.")
70
+ ![kovid](https://i.gyazo.com/be3bcba3d2943c60618b59ae82a3c586.png "Covid data.")
71
71
 
72
72
  To compare a countries stats with a full table:
73
73
 
74
74
  `kovid compare poland italy usa china -f` OR `kovid compare poland italy usa china --full`
75
75
 
76
- ![kovid](https://i.gyazo.com/7ce86c5e93d549e1412fb6104a1d7877.png "Covid data.")
76
+ ![kovid](https://i.gyazo.com/79ad61c33114a0bee0a9e2ab94a3d46e.png "Covid data.")
77
77
 
78
78
  To fetch state-specific data run:
79
79
 
80
80
  `kovid state colorado`
81
81
 
82
- ![kovid](https://i.gyazo.com/133046d9d31c20a8bad1a05b46ba4d3e.png "Covid data.")
82
+ ![kovid](https://i.gyazo.com/d00b1c5bbb6251cbd517f801c856ba66.png "Covid data.")
83
83
 
84
84
  To check for total figures:
85
85
 
86
86
  `kovid cases`
87
87
 
88
- ![kovid](https://i.gyazo.com/f8a21ae54152cd945fbb124b72d12ff7.png "Covid data.")
88
+ ![kovid](https://i.gyazo.com/323f0f10d444e2ee629d05a90488adba.png "Covid data.")
89
89
 
90
- ## Source
90
+ ## Information Source
91
91
  > https://www.worldometers.info/coronavirus/ via [NovelCOVID/API](https://github.com/novelcovid/api)
92
92
 
93
93
 
@@ -100,7 +100,7 @@ To install this gem onto your local machine, run `bundle exec rake install`.
100
100
 
101
101
  ## 🤲 Contributing
102
102
 
103
- There are multiple areas in this repo that can be improved or use some refactoring. For that reason, bug reports and pull requests are welcome here on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/siaw23/kovid/blob/master/CODE_OF_CONDUCT.md).
103
+ There are multiple areas in this repo that can be improved or use some refactoring(there's a lot to be refactorted in fact!). For that reason, bug reports and pull requests are welcome! This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/siaw23/kovid/blob/master/CODE_OF_CONDUCT.md).
104
104
 
105
105
 
106
106
  ## 🔖 License
data/exe/covid CHANGED
File without changes
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Emmanuel Hayford"]
7
7
  spec.email = ["siawmensah@gmail.com"]
8
8
 
9
- spec.summary = %q{🦠 A CLI tool to fetch and compare the 2019 coronavirus pandemic numbers.}
10
- spec.description = %q{A CLI tool to fetch and compare the 2019 coronavirus pandemic numbers.}
9
+ spec.summary = %q{A CLI to fetch and compare the 2019 coronavirus pandemic statistics.}
10
+ spec.description = %q{A CLI to fetch and compare the 2019 coronavirus pandemic statistics.}
11
11
  spec.homepage = "https://github.com/siaw23/kovid"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "thor"
31
31
  spec.add_dependency "terminal-table"
32
32
  spec.add_dependency "typhoeus"
33
+ spec.add_dependency "colorize"
33
34
 
34
35
  spec.add_development_dependency "pry"
35
36
  spec.add_development_dependency "cucumber"
@@ -1,8 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'kovid/version'
4
- require 'kovid/nineteen'
4
+ require 'kovid/request'
5
5
 
6
6
  module Kovid
7
7
  class Error < StandardError; end
8
+
9
+ module_function
10
+
11
+ def whatis
12
+ 'Coronavirus disease 2019 (COVID-19) is an infectious disease caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2).'
13
+ end
14
+
15
+ def country(name)
16
+ Kovid::Request.by_country(name)
17
+ end
18
+
19
+ def country_full(name)
20
+ Kovid::Request.by_country_full(name)
21
+ end
22
+
23
+ def state(state)
24
+ Kovid::Request.state(state)
25
+ end
26
+
27
+ def country_comparison(names_array)
28
+ Kovid::Request.by_country_comparison(names_array)
29
+ end
30
+
31
+ def country_comparison_full(names_array)
32
+ Kovid::Request.by_country_comparison_full(names_array)
33
+ end
34
+
35
+ def cases
36
+ Kovid::Request.cases
37
+ end
8
38
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'typhoeus'
4
+
5
+ module Kovid
6
+ class Cache
7
+ def initialize
8
+ @memory = {}
9
+ end
10
+
11
+ def get(request)
12
+ @memory[request]
13
+ end
14
+
15
+ def set(request, response)
16
+ @memory[request] = response
17
+ end
18
+ end
19
+
20
+ Typhoeus::Config.cache = Cache.new
21
+ end
@@ -9,37 +9,39 @@ module Kovid
9
9
 
10
10
  desc 'define', 'Defines COVID-19'
11
11
  def define
12
- puts Kovid::Nineteen.whatis
12
+ puts Kovid.whatis
13
13
  end
14
14
 
15
- desc 'check COUNTRY', 'Returns reported data on provided country'
15
+ desc 'check COUNTRY or check "COUNTRY NAME"', 'Returns reported data on provided country. eg: "kovid check "hong kong".'
16
16
  method_option :full, aliases: '-f'
17
17
  def check(name)
18
18
  if options[:full]
19
- puts Kovid::Nineteen.country_full(name)
19
+ puts Kovid.country_full(name)
20
20
  else
21
- puts Kovid::Nineteen.country(name)
21
+ puts Kovid.country(name)
22
22
  end
23
23
  end
24
+ desc 'country COUNTRY or country "COUNTRY NAME"', 'Returns reported data on provided country. eg: "kovid country "hong kong".'
25
+ alias country check
24
26
 
25
- desc 'state STATE', 'Return reported data on provided state'
27
+ desc 'state STATE', 'Return reported data on provided state.'
26
28
  def state(state)
27
- puts Kovid::Nineteen.state(state)
29
+ puts Kovid.state(state)
28
30
  end
29
31
 
30
- desc 'compare COUNTRY COUNTRY', 'Returns full comparison table for given countries. Accepts multiple countries'
32
+ desc 'compare COUNTRY COUNTRY', 'Returns full comparison table for given countries. Accepts multiple countries.'
31
33
  def compare(*name)
32
34
  if FULL_FLAG.include?(name.fetch(-1))
33
35
  name = name.reverse.drop(1).reverse
34
- puts Kovid::Nineteen.country_comparison_full(name)
36
+ puts Kovid.country_comparison_full(name)
35
37
  else
36
- puts Kovid::Nineteen.country_comparison(name)
38
+ puts Kovid.country_comparison(name)
37
39
  end
38
40
  end
39
41
 
40
- desc 'cases', 'Returns total number of cases, deaths and recoveries'
42
+ desc 'cases', 'Returns total number of cases, deaths and recoveries.'
41
43
  def cases
42
- puts Kovid::Nineteen.cases
44
+ puts Kovid.cases
43
45
  end
44
46
  end
45
47
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorize'
4
+
5
+ class String
6
+ def paint_white
7
+ colorize(:white).colorize(background: :black).colorize(mode: :bold)
8
+ end
9
+
10
+ def paint_red
11
+ colorize(:red).colorize(background: :black).colorize(mode: :bold)
12
+ end
13
+
14
+ def paint_green
15
+ colorize(:green).colorize(background: :black).colorize(mode: :bold)
16
+ end
17
+
18
+ def paint_yellow
19
+ colorize(:yellow).colorize(background: :black).colorize(mode: :bold)
20
+ end
21
+ end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'typhoeus'
4
3
  require 'json'
5
4
  require_relative 'tablelize'
5
+ require_relative 'cache'
6
6
 
7
7
  module Kovid
8
8
  class Request
@@ -45,17 +45,16 @@ module Kovid
45
45
  path = '/all'
46
46
  fetch_url = BASE_URL + path
47
47
 
48
- response ||= JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
48
+ response ||= JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 900).response_body)
49
+
49
50
  Kovid::Tablelize.cases(response)
50
51
  end
51
52
 
52
53
  private
53
54
 
54
55
  def no_case_in(country)
55
- rows = []
56
- rows << ["Thankfully, there are no reported cases in #{country.capitalize}!"]
57
- table = Terminal::Table.new headings: [country.capitalize.to_s], rows: rows
58
- table
56
+ rows = [["Thankfully, there are no reported cases in #{country.capitalize}!"]]
57
+ Terminal::Table.new headings: [country.capitalize.to_s], rows: rows
59
58
  end
60
59
 
61
60
  def fetch_countries(list)
@@ -65,7 +64,7 @@ module Kovid
65
64
  path = "/countries/#{country}"
66
65
  fetch_url = BASE_URL + path
67
66
 
68
- array << JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
67
+ array << JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 900).response_body)
69
68
  end
70
69
 
71
70
  array = array.sort_by { |json| -json['cases'] }
@@ -75,14 +74,14 @@ module Kovid
75
74
  path = "/countries/#{country_name}"
76
75
  fetch_url = BASE_URL + path
77
76
 
78
- JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
77
+ JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 900).response_body)
79
78
  end
80
79
 
81
80
  def fetch_state(state)
82
81
  path = '/states'
83
82
  fetch_url = BASE_URL + path
84
83
 
85
- states_array = JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
84
+ states_array = JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 900).response_body)
86
85
 
87
86
  states_array.select { |state_name| state_name['state'] == state.split.map(&:capitalize).join(' ') }.first
88
87
  end
@@ -1,26 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'terminal-table'
4
+ require_relative 'painter'
4
5
 
5
6
  module Kovid
6
7
  class Tablelize
7
8
  class << self
9
+ CASES_DEATHS_RECOVERED = [
10
+ 'Cases'.paint_white,
11
+ 'Deaths'.paint_red,
12
+ 'Recovered'.paint_green
13
+ ].freeze
14
+
8
15
  def country_table(data)
9
- headings = %w[Cases Deaths Recovered]
10
- rows = []
11
- rows << [data['cases'], data['deaths'], data['recovered']]
16
+ headings = CASES_DEATHS_RECOVERED
17
+ rows = [[data['cases'], data['deaths'], data['recovered']]]
18
+
12
19
  Terminal::Table.new(title: data['country'], headings: headings, rows: rows)
13
20
  end
14
21
 
15
22
  def full_country_table(data)
16
23
  headings = [
17
- 'Cases',
18
- 'Deaths',
19
- 'Recovered',
20
- 'Cases Today',
21
- 'Deaths Today',
22
- 'Critical',
23
- 'Cases/Million'
24
+ 'Cases'.paint_white,
25
+ 'Deaths'.paint_red,
26
+ 'Recovered'.paint_green,
27
+ 'Cases Today'.paint_white,
28
+ 'Deaths Today'.paint_red,
29
+ 'Critical'.paint_yellow,
30
+ 'Cases/Million'.paint_white
24
31
  ]
25
32
 
26
33
  rows = []
@@ -39,14 +46,28 @@ module Kovid
39
46
  end
40
47
 
41
48
  def full_state_table(state)
42
- headings = ['Cases', 'Cases Today', 'Deaths', 'Deaths Today', 'Reovered', 'Active']
49
+ headings = [
50
+ 'Cases'.paint_white,
51
+ 'Cases Today',
52
+ 'Deaths'.paint_red,
53
+ 'Deaths Today'.paint_red,
54
+ 'Reovered'.paint_green,
55
+ 'Active'.paint_yellow
56
+ ]
57
+
43
58
  rows = []
44
59
  rows << [state['cases'], state['todayCases'], state['deaths'], state['todayDeaths'], state['recovered'], state['active']]
45
60
  Terminal::Table.new(title: state['state'], headings: headings, rows: rows)
46
61
  end
47
62
 
48
63
  def compare_countries_table(data)
49
- headings = %w[Country Cases Deaths Recovered]
64
+ headings = [
65
+ 'Country'.paint_white,
66
+ 'Cases'.paint_white,
67
+ 'Deaths'.paint_red,
68
+ 'Recovered'.paint_green
69
+ ]
70
+
50
71
  rows = []
51
72
 
52
73
  data.each do |country|
@@ -58,15 +79,16 @@ module Kovid
58
79
 
59
80
  def compare_countries_table_full(data)
60
81
  headings = [
61
- 'Country',
62
- 'Cases',
63
- 'Deaths',
64
- 'Recovered',
65
- 'Cases Today',
66
- 'Deaths Today',
67
- 'Critical',
68
- 'Cases/Million'
82
+ 'Country'.paint_white,
83
+ 'Cases'.paint_white,
84
+ 'Deaths'.paint_red,
85
+ 'Recovered'.paint_green,
86
+ 'Cases Today'.paint_white,
87
+ 'Deaths Today'.paint_red,
88
+ 'Critical'.paint_yellow,
89
+ 'Cases/Million'.paint_white
69
90
  ]
91
+
70
92
  rows = []
71
93
 
72
94
  data.each do |country|
@@ -86,11 +108,9 @@ module Kovid
86
108
  end
87
109
 
88
110
  def cases(cases)
89
- headings = %w[Cases Deaths Recoveries]
90
-
91
- rows = []
111
+ headings = CASES_DEATHS_RECOVERED
112
+ rows = [[cases['cases'], cases['deaths'], cases['recovered']]]
92
113
 
93
- rows << [cases['cases'], cases['deaths'], cases['recovered']]
94
114
  Terminal::Table.new(title: 'Total # of incidents', headings: headings, rows: rows)
95
115
  end
96
116
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.1.13'
4
+ VERSION = '0.1.14'
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.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Hayford
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: pry
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +122,7 @@ dependencies:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
- description: A CLI tool to fetch and compare the 2019 coronavirus pandemic numbers.
125
+ description: A CLI to fetch and compare the 2019 coronavirus pandemic statistics.
112
126
  email:
113
127
  - siawmensah@gmail.com
114
128
  executables:
@@ -132,8 +146,9 @@ files:
132
146
  - exe/kovid
133
147
  - kovid.gemspec
134
148
  - lib/kovid.rb
149
+ - lib/kovid/cache.rb
135
150
  - lib/kovid/cli.rb
136
- - lib/kovid/nineteen.rb
151
+ - lib/kovid/painter.rb
137
152
  - lib/kovid/request.rb
138
153
  - lib/kovid/tablelize.rb
139
154
  - lib/kovid/version.rb
@@ -163,6 +178,5 @@ requirements: []
163
178
  rubygems_version: 3.1.2
164
179
  signing_key:
165
180
  specification_version: 4
166
- summary: "\U0001F9A0 A CLI tool to fetch and compare the 2019 coronavirus pandemic
167
- numbers."
181
+ summary: A CLI to fetch and compare the 2019 coronavirus pandemic statistics.
168
182
  test_files: []
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'request'
4
-
5
- module Kovid
6
- class Nineteen
7
- class << self
8
- def whatis
9
- 'Coronavirus disease 2019 (COVID-19) is an infectious disease caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2).'
10
- end
11
-
12
- def country(name)
13
- Kovid::Request.by_country(name)
14
- end
15
-
16
- def country_full(name)
17
- Kovid::Request.by_country_full(name)
18
- end
19
-
20
- def state(state)
21
- Kovid::Request.state(state)
22
- end
23
-
24
- def country_comparison(names_array)
25
- Kovid::Request.by_country_comparison(names_array)
26
- end
27
-
28
- def country_comparison_full(names_array)
29
- Kovid::Request.by_country_comparison_full(names_array)
30
- end
31
-
32
- def cases
33
- Kovid::Request.cases
34
- end
35
- end
36
- end
37
- end