kovid 0.2.6 β†’ 0.3.2

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: fdb8dfafa7894028f398f20f933b498c405d56bfc3ef4a5d7a339a83276a7d6d
4
- data.tar.gz: 30eb0c8ce98ee989185cf81f8bba72f5c993bdc6a44a229b7ba2a9131e31b1ae
3
+ metadata.gz: d4205df6f2e487214f535dda994a132264a9966b6c7527dec22f908f7aad76ed
4
+ data.tar.gz: 24b98f27cddcff29ed2a75d02be4af8d81fb2078d138890d75c9fb3541207bdf
5
5
  SHA512:
6
- metadata.gz: bdf67215185377506876eb06937b1e9592c4e29d984b1f8458296acc3d23f1ff6162f64864ebb430906a1e70e3005d80ff226fc51c7eb8ecb9a07164dd9019f1
7
- data.tar.gz: d7d350545f13bd7ebee3987e0af9a3d23968f229ef7c87d70da5536bdcb5064525093988ab1f5ee16b7bf3b07d25c164368e742b5bcc075b71768d2a98b08b47
6
+ metadata.gz: 2c5e2f6b14c57dc707d81f5711ea6d2004300d253f8ba7afb0d453d14bd2f73210de62d73d2457caf7ed221ad8d27b192db2e511e749903bb25cd31bbfe3be02
7
+ data.tar.gz: 7fc35f3888744cbadcfe131e080ef56a3d9b0055f8437316f5286f364ab71391a6322df951c86c707ab43d3669b839aaed58fa3108913c36d6d252ce3759dca5
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.2.5)
5
- colorize (~> 0.8)
4
+ kovid (0.3.1)
5
+ rainbow (~> 3.0)
6
6
  terminal-table (~> 1.8)
7
7
  thor (~> 1.0)
8
8
  typhoeus (~> 1.3)
@@ -21,7 +21,6 @@ GEM
21
21
  builder (3.2.4)
22
22
  childprocess (3.0.0)
23
23
  coderay (1.1.2)
24
- colorize (0.8.1)
25
24
  contracts (0.16.0)
26
25
  cucumber (3.1.2)
27
26
  builder (>= 2.1.2)
@@ -51,6 +50,7 @@ GEM
51
50
  pry (0.12.2)
52
51
  coderay (~> 1.1.0)
53
52
  method_source (~> 0.9.0)
53
+ rainbow (3.0.0)
54
54
  rake (12.3.3)
55
55
  rspec (3.9.0)
56
56
  rspec-core (~> 3.9.0)
@@ -89,4 +89,4 @@ DEPENDENCIES
89
89
  simplecov
90
90
 
91
91
  BUNDLED WITH
92
- 2.1.2
92
+ 2.1.4
data/README.md CHANGED
@@ -1,57 +1,55 @@
1
1
  # 🦠 Kovid
2
2
 
3
- [gem]: https://rubygems.org/gems/kovid
4
-
5
- Kovid is a small CLI app to fetch data surrounding the coronavirus pandemic of 2019. I found myself checking [Wikipedia](https://en.wikipedia.org/wiki/2019%E2%80%9320_coronavirus_pandemic) constantly for information and since I work mostly in the terminal, like some of you, I thought I'd build this to put the data right at our fingertips.
3
+ Kovid is a small CLI app to fetch data surrounding the coronavirus pandemic of 2019. I found myself checking [Wikipedia](https://en.wikipedia.org/wiki/2019%E2%80%9320_coronavirus_pandemic) constantly for information so I thought I'd build this to provide info directly in the terminal. It's where some of us spend time more.
6
4
 
7
5
  Code contribution and ideas welcome.
8
6
 
9
7
 
10
8
  ## βš™οΈ Installation
11
9
 
12
- Before installing:
13
-
14
- ☝️ Wash your hands with soap and water for at least 20 seconds.
10
+ To install:
15
11
 
16
- ✌️ Run `gem install kovid`
12
+ * ️ Wash your hands with soap and water for at least 20 seconds.
17
13
 
14
+ * Run `gem install kovid`.
18
15
 
16
+ It's recommended you update often with `gem update kovid`.
19
17
 
20
18
  ## βš’οΈ Usage
21
19
 
22
20
  You can run `kovid --help` to see the full list of available commands.
23
21
 
24
- **NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
25
-
26
22
  #### Commands Overview
27
23
  😷 **Fetching**
28
- * `kovid check COUNTRY` (`kovid country COUNTRY` works as well)
29
- * `kovid check COUNTRY -f` OR `kovid check COUNTRY --full`
24
+ * `kovid check COUNTRY` OR `kovid country COUNTRY`.
25
+ * `kovid check COUNTRY -f` OR `kovid check COUNTRY --full`.
26
+
27
+ πŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡Έ
30
28
 
31
- πŸ‡ΊπŸ‡ΈYou can fetch US state-specific data πŸ‡ΊπŸ‡Έ
32
- * `kovid state STATE` OR `kovid state "STATE WITH SPACES"`
29
+ You can fetch US state-specific data:
30
+ * `kovid state STATE` OR `kovid state "STATE NAME"`.
33
31
 
34
32
  😷 **Comparing**
35
- * `kovid compare COUNTRYA COUNTRYB` (sorts by cases DESC)
36
- * `kovid compare COUNTRYA COUNTRYB -f` OR `kovid compare COUNTRYA COUNTRYB --full` (sorts by cases DESC)
33
+ * `kovid compare FOO BAR` (sorts by cases DESC).
34
+ * `kovid compare FOO BAR -f` OR `kovid compare FOO BAR --full` (sorts by cases DESC).
37
35
 
38
- You can compare as many countries as you want.
36
+ Where `FOO` and `BAR` are different countries.
37
+
38
+ You can compare as many countries as you want; `kovid compare FOO BAR BAZ` OR `kovid compare FOO BAR BAZ -f`
39
39
 
40
40
  😷 **History**
41
- * `kovid history COUNTRY` (full history)
42
- * `kovid history COUNTRY N` (history in the last N days)
41
+ * `kovid history COUNTRY` (full history).
42
+ * `kovid history COUNTRY N` (history in the last N days).
43
43
 
44
44
  😷 **Total figures**
45
- * `kovid cases`
46
-
45
+ * `kovid cases` (summary of reported incidents globally).
47
46
 
47
+ **NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
48
48
 
49
49
  #### Commands Details
50
50
  To fetch basic data on a country run:
51
51
 
52
- `kovid check ghana`
53
-
54
- If the location contains spaces: `kovid check "Diamond Princess"`
52
+ `kovid check ghana`. If the location contains spaces: `kovid check "Diamond Princess"`
55
53
 
56
54
  ![kovid](https://i.gyazo.com/ab779c3fc838ac279bae5b9d6d10d617.png "Covid data.")
57
55
 
@@ -104,7 +102,7 @@ To install this gem onto your local machine, run `bundle exec rake install`.
104
102
 
105
103
  ## 🀲 Contributing
106
104
 
107
- 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).
105
+ There are multiple areas in this repo that can be improved or use some refactoring(there's a lot to be refactored 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).
108
106
 
109
107
 
110
108
  ## πŸ”– License
@@ -14,6 +14,29 @@ Gem::Specification.new do |spec|
14
14
 
15
15
  spec.metadata["allowed_push_host"] = "https://rubygems.org/"
16
16
 
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/siaw23/kovid"
19
+ spec.metadata["changelog_uri"] = "https://github.com/siaw23/kovid"
20
+
21
+ spec.add_dependency "thor", "~> 1.0"
22
+ spec.add_dependency "terminal-table", "~> 1.8"
23
+ spec.add_dependency "typhoeus", "~> 1.3"
24
+ spec.add_dependency "rainbow", "~> 3.0"
25
+
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "cucumber"
28
+ spec.add_development_dependency "aruba"
29
+ spec.add_development_dependency "simplecov"
30
+
31
+ # 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 that have been added into git.
33
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
34
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35
+ end
36
+ spec.bindir = "exe"
37
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
+ spec.require_paths = ["lib"]
39
+
17
40
  spec.post_install_message = %q{
18
41
  ============================================================================
19
42
  COVID-19 has devasted the world. But while we're fighting
@@ -31,27 +54,4 @@ Gem::Specification.new do |spec|
31
54
  Emmanuel Hayford.
32
55
  ============================================================================
33
56
  }
34
-
35
- spec.metadata["homepage_uri"] = spec.homepage
36
- spec.metadata["source_code_uri"] = "https://github.com/siaw23/kovid"
37
- spec.metadata["changelog_uri"] = "https://github.com/siaw23/kovid"
38
-
39
- # Specify which files should be added to the gem when it is released.
40
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
41
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
42
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
43
- end
44
- spec.bindir = "exe"
45
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
46
- spec.require_paths = ["lib"]
47
-
48
- spec.add_dependency "thor", "~> 1.0"
49
- spec.add_dependency "terminal-table", "~> 1.8"
50
- spec.add_dependency "typhoeus", "~> 1.3"
51
- spec.add_dependency "colorize", "~> 0.8"
52
-
53
- spec.add_development_dependency "pry"
54
- spec.add_development_dependency "cucumber"
55
- spec.add_development_dependency "aruba"
56
- spec.add_development_dependency "simplecov"
57
57
  end
@@ -15,14 +15,14 @@ module Kovid
15
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
- if options[:full]
19
- puts Kovid.country_full(name)
20
- else
21
- puts Kovid.country(name)
22
- end
18
+ fetch_country_stats(name)
23
19
  end
20
+
24
21
  desc 'country COUNTRY or country "COUNTRY NAME"', 'Returns reported data on provided country. eg: "kovid country "hong kong".'
25
- alias country check
22
+ method_option :full, aliases: '-f'
23
+ def country(name)
24
+ fetch_country_stats(name)
25
+ end
26
26
 
27
27
  desc 'state STATE', 'Return reported data on provided state.'
28
28
  def state(state)
@@ -51,5 +51,15 @@ module Kovid
51
51
  puts Kovid.history(params.first, nil)
52
52
  end
53
53
  end
54
+
55
+ private
56
+
57
+ def fetch_country_stats(country)
58
+ if options[:full]
59
+ puts Kovid.country_full(country)
60
+ else
61
+ puts Kovid.country(country)
62
+ end
63
+ end
54
64
  end
55
65
  end
@@ -1,21 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'colorize'
3
+ require 'rainbow'
4
4
 
5
5
  class String
6
6
  def paint_white
7
- colorize(:white).colorize(background: :black).colorize(mode: :bold)
7
+ Rainbow(self).white.bg(:black).bold
8
8
  end
9
9
 
10
10
  def paint_red
11
- colorize(:red).colorize(background: :black).colorize(mode: :bold)
11
+ Rainbow(self).red.bg(:black).bold
12
12
  end
13
13
 
14
14
  def paint_green
15
- colorize(:green).colorize(background: :black).colorize(mode: :bold)
15
+ Rainbow(self).green.bg(:black).bold
16
16
  end
17
17
 
18
18
  def paint_yellow
19
- colorize(:yellow).colorize(background: :black).colorize(mode: :bold)
19
+ Rainbow(self).yellow.bg(:black).bold
20
20
  end
21
21
  end
@@ -8,6 +8,7 @@ require_relative 'uri_builder'
8
8
  module Kovid
9
9
  class Request
10
10
  COUNTRIES_PATH = UriBuilder.new('/countries').url
11
+ STATES_URL = UriBuilder.new('/states').url
11
12
 
12
13
  class << self
13
14
  def by_country(country_name)
@@ -58,8 +59,8 @@ module Kovid
58
59
  private
59
60
 
60
61
  def no_case_in(country)
61
- rows = [['No reported cases OR wrong spelling of country/state!']]
62
- Terminal::Table.new headings: ["You checked: #{country.capitalize}"], rows: rows
62
+ rows = [["Wrong spelling of location/API has no info on #{country.upcase} at the moment."]]
63
+ Terminal::Table.new title: "You checked: #{country.upcase}", rows: rows
63
64
  end
64
65
 
65
66
  def fetch_countries(list)
@@ -73,21 +74,17 @@ module Kovid
73
74
  end
74
75
 
75
76
  def fetch_country(country_name)
76
- url = COUNTRIES_PATH + "/#{country_name}"
77
+ country_url = COUNTRIES_PATH + "/#{country_name}"
77
78
 
78
- JSON.parse(Typhoeus.get(url, cache_ttl: 900).response_body)
79
+ JSON.parse(Typhoeus.get(country_url, cache_ttl: 900).response_body)
79
80
  end
80
81
 
81
82
  def fetch_state(state)
82
- url = UriBuilder.new('/states').url
83
-
84
- states_array = JSON.parse(Typhoeus.get(url, cache_ttl: 900).response_body)
83
+ states_array = JSON.parse(Typhoeus.get(STATES_URL, cache_ttl: 900).response_body)
85
84
 
86
85
  states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
87
86
  end
88
87
 
89
- private
90
-
91
88
  def capitalize_words(string)
92
89
  string.split.map(&:capitalize).join(' ')
93
90
  end
@@ -21,12 +21,19 @@ module Kovid
21
21
  ].freeze
22
22
 
23
23
  FOOTER_LINE = ['------------', '------------', '------------', '------------'].freeze
24
+ COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
24
25
 
25
26
  def country_table(data)
26
27
  headings = CASES_DEATHS_RECOVERED
27
28
  rows = [[data['cases'], data['deaths'], data['recovered']]]
28
29
 
29
- Terminal::Table.new(title: data['country'].upcase, headings: headings, rows: rows)
30
+ if iso = data['countryInfo']['iso2']
31
+ Terminal::Table.new(title: data['country'].upcase.to_s, headings: headings, rows: rows)
32
+ else
33
+ Terminal::Table.new(title: data['country'].upcase, headings: headings, rows: rows)
34
+ end
35
+ # TODO: Rafactor this
36
+ # TODO: Fix emoji
30
37
  end
31
38
 
32
39
  def full_country_table(data)
@@ -45,14 +52,22 @@ module Kovid
45
52
  data['cases'],
46
53
  data['deaths'],
47
54
  data['recovered'],
48
- data['todayCases'],
49
- data['todayDeaths'],
55
+ check_if_positve(data['todayCases']),
56
+ check_if_positve(data['todayDeaths']),
50
57
  data['critical'],
51
58
  data['casesPerOneMillion']
52
59
  ]
60
+
61
+ # if iso = data['countryInfo']['iso2']
62
+ # Terminal::Table.new(title: "#{data['country'].upcase} #{country_emoji(iso)}",
63
+ # headings: headings,
64
+ # rows: rows)
65
+ # else
53
66
  Terminal::Table.new(title: data['country'].upcase,
54
67
  headings: headings,
55
68
  rows: rows)
69
+ # end
70
+ # TODO: Rafactor this
56
71
  end
57
72
 
58
73
  def full_state_table(state)
@@ -61,12 +76,11 @@ module Kovid
61
76
  'Cases Today'.paint_white,
62
77
  'Deaths'.paint_red,
63
78
  'Deaths Today'.paint_red,
64
- 'Recovered'.paint_green,
65
79
  'Active'.paint_yellow
66
80
  ]
67
81
 
68
82
  rows = []
69
- rows << [state['cases'], state['todayCases'], state['deaths'], state['todayDeaths'], state['recovered'], state['active']]
83
+ rows << [state['cases'], check_if_positve(state['todayCases']), state['deaths'], check_if_positve(state['todayDeaths']), state['active']]
70
84
 
71
85
  Terminal::Table.new(title: state['state'].upcase, headings: headings, rows: rows)
72
86
  end
@@ -82,7 +96,7 @@ module Kovid
82
96
  rows = []
83
97
 
84
98
  data.each do |country|
85
- rows << [country['country'].upcase, country['cases'], country['deaths'], country['recovered']]
99
+ rows << [country['country'].upcase, comma_delimit(country['cases']), comma_delimit(country['deaths']), comma_delimit(country['recovered'])]
86
100
  end
87
101
 
88
102
  Terminal::Table.new(headings: headings, rows: rows)
@@ -105,13 +119,13 @@ module Kovid
105
119
  data.each do |country|
106
120
  rows << [
107
121
  country['country'],
108
- country['cases'],
109
- country['deaths'],
110
- country['recovered'],
111
- country['todayCases'],
112
- country['todayDeaths'],
113
- country['critical'],
114
- country['casesPerOneMillion']
122
+ comma_delimit(country['cases']),
123
+ comma_delimit(country['deaths']),
124
+ comma_delimit(country['recovered']),
125
+ check_if_positve(country['todayCases']),
126
+ check_if_positve(country['todayDeaths']),
127
+ comma_delimit(country['critical']),
128
+ comma_delimit(country['casesPerOneMillion'])
115
129
  ]
116
130
  end
117
131
 
@@ -120,7 +134,13 @@ module Kovid
120
134
 
121
135
  def cases(cases)
122
136
  headings = CASES_DEATHS_RECOVERED
123
- rows = [[cases['cases'], cases['deaths'], cases['recovered']]]
137
+ rows = [
138
+ [
139
+ comma_delimit(cases['cases']),
140
+ comma_delimit(cases['deaths']),
141
+ comma_delimit(cases['recovered'])
142
+ ]
143
+ ]
124
144
 
125
145
  Terminal::Table.new(title: 'Total Number of Incidents Worldwide'.upcase, headings: headings, rows: rows)
126
146
  end
@@ -164,6 +184,14 @@ module Kovid
164
184
  def comma_delimit(number)
165
185
  number.to_s.chars.to_a.reverse.each_slice(3).map(&:join).join(',').reverse
166
186
  end
187
+
188
+ def check_if_positve(num)
189
+ num.to_i.positive? ? "+#{comma_delimit(num)}" : comma_delimit(num).to_s
190
+ end
191
+
192
+ def country_emoji(iso)
193
+ COUNTRY_LETTERS.values_at(*iso.chars).pack('U*')
194
+ end
167
195
  end
168
196
  end
169
197
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.2.6'
4
+ VERSION = '0.3.2'
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.2.6
4
+ version: 0.3.2
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-24 00:00:00.000000000 Z
11
+ date: 2020-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: colorize
56
+ name: rainbow
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.8'
61
+ version: '3.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.8'
68
+ version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement