kovid 0.2.4 β†’ 0.2.5

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: c9550f7e2c21e089e88674eaa7be67f06afe3a10d3a3c06d4afa25c5bd694c5f
4
- data.tar.gz: 910479f761ce923dbce855a4e466cf2d9b8d653bac427be77807357fccbb4a91
3
+ metadata.gz: b453d783796a94766fee3d796a41070ae4a1708c8a306a8b77ae60a912293a78
4
+ data.tar.gz: 85ff2d518cd223ab521f6c1221151745a75269605288fcd5882f569871bbc0eb
5
5
  SHA512:
6
- metadata.gz: 0f5109a811d7f3986ced3b55ac1794a26e2e4abe8f13f7b9bf228f184bb9c6e66cac1be7d28426c40e58c3d231a220994eedb33061f1f013bae0fc39db27f5d7
7
- data.tar.gz: cdaa6de69ccc6c13a56749c15bf0a5c19ac2b25e4cb5db73e1ed2257f51c0e2695a9885636575e491eabc3f38a7655725b3fba3412d46e4dbd34ca038e7a6d4a
6
+ metadata.gz: 9d4d98b52a3eea164950abbb4639c97aacd95f3a3cce00f8d211c558ec5fc3f97bbb26bf2b97aab69ad95bbc897c77c9a65bd66a97e5f3021bb48adc23e007af
7
+ data.tar.gz: 19f9ce8011ecf1383c71787fd9bc853d4fef3d3df2bbb6d63010e0a4bffa6708d895ed05547c4db6629f9fe84028dc614e0b9de5951b603f8fd2e162b7de6473
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.2.2)
5
- colorize
6
- terminal-table
7
- thor
8
- typhoeus
4
+ kovid (0.2.4)
5
+ colorize (~> 0.8)
6
+ terminal-table (~> 1.8)
7
+ thor (~> 1.0)
8
+ typhoeus (~> 1.3)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -20,24 +20,25 @@ Before installing:
20
20
 
21
21
  You can run `kovid --help` to see the full list of available commands.
22
22
 
23
- **NOTE:** If you find it irritating to have to type `kovid state michigan`, `covid state michigan` works as well.
23
+ **NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
24
24
 
25
25
  #### Commands Overview
26
26
  😷 **Fetching**
27
- * `kovid check ghana`
28
- * `kovid check italy -f` OR `kovid check italy --full`
27
+ * `kovid check COUNTRY`
28
+ * `kovid check COUNTRY -f` OR `kovid check COUNTRY --full`
29
29
 
30
30
  πŸ‡ΊπŸ‡ΈYou can fetch US state-specific data πŸ‡ΊπŸ‡Έ
31
- * `kovid state colorado` OR `kovid state "north carolina"`
31
+ * `kovid state STATE` OR `kovid state "STATE WITH SPACES"`
32
32
 
33
33
  😷 **Comparing**
34
- * `kovid compare ghana poland` (sorts by cases DESC)
35
- * `kovid compare germany poland -f` OR `kovid compare germany poland --full` (sorts by cases DESC)
34
+ * `kovid compare COUNTRYA COUNTRYB` (sorts by cases DESC)
35
+ * `kovid compare COUNTRYA COUNTRYB -f` OR `kovid compare COUNTRYA COUNTRYB --full` (sorts by cases DESC)
36
36
 
37
37
  You can compare as many countries as you want.
38
38
 
39
39
  😷 **History**
40
- * `kovid history italy`
40
+ * `kovid history COUNTRY` (Full history)
41
+ * `kovid history COUNTRY N` (History in the last N days)
41
42
 
42
43
  😷 **Total figures**
43
44
  * `kovid cases`
@@ -73,15 +74,15 @@ To compare a countries stats with a full table:
73
74
 
74
75
  To fetch state-specific data run:
75
76
 
76
- `kovid state colorado`
77
+ `kovid state colorado` OR `kovid state "north carolina"`
77
78
 
78
79
  ![kovid](https://i.gyazo.com/d00b1c5bbb6251cbd517f801c856ba66.png "Covid data.")
79
80
 
80
81
  You can check historical statistics by running
81
82
 
82
- `kovid history COUNTRY` eg:
83
+ `kovid history italy 7` eg:
83
84
 
84
- ![kovid](https://i.gyazo.com/45d306694cbf793f2e4f7646854cbac8.png "Covid data.")
85
+ ![kovid](https://i.gyazo.com/e4872b5047eeaebbd354847a943de268.png "Covid data.")
85
86
 
86
87
  To check for total figures:
87
88
 
data/kovid.gemspec CHANGED
@@ -45,10 +45,10 @@ Gem::Specification.new do |spec|
45
45
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
46
46
  spec.require_paths = ["lib"]
47
47
 
48
- spec.add_dependency "thor"
49
- spec.add_dependency "terminal-table"
50
- spec.add_dependency "typhoeus"
51
- spec.add_dependency "colorize"
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
52
 
53
53
  spec.add_development_dependency "pry"
54
54
  spec.add_development_dependency "cucumber"
data/lib/kovid/cli.rb CHANGED
@@ -44,8 +44,12 @@ module Kovid
44
44
  end
45
45
 
46
46
  desc 'history COUNTRY', 'Return history of incidents of COUNTRY'
47
- def history(country)
48
- puts Kovid.history(country)
47
+ def history(*params)
48
+ if params.size == 2
49
+ puts Kovid.history(params.first, params.last)
50
+ else
51
+ puts Kovid.history(params.first, nil)
52
+ end
49
53
  end
50
54
  end
51
55
  end
data/lib/kovid/request.rb CHANGED
@@ -48,11 +48,11 @@ module Kovid
48
48
  Kovid::Tablelize.cases(response)
49
49
  end
50
50
 
51
- def history(country)
51
+ def history(country, last)
52
52
  history_path = UriBuilder.new('/historical').url
53
53
  response ||= JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
54
54
 
55
- Kovid::Tablelize.history(response)
55
+ Kovid::Tablelize.history(response, last)
56
56
  end
57
57
 
58
58
  private
@@ -80,6 +80,7 @@ module Kovid
80
80
 
81
81
  def fetch_state(state)
82
82
  url = UriBuilder.new('/states').url
83
+
83
84
  states_array = JSON.parse(Typhoeus.get(url, cache_ttl: 900).response_body)
84
85
 
85
86
  states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
@@ -26,7 +26,7 @@ module Kovid
26
26
  headings = CASES_DEATHS_RECOVERED
27
27
  rows = [[data['cases'], data['deaths'], data['recovered']]]
28
28
 
29
- Terminal::Table.new(title: data['country'], headings: headings, rows: rows)
29
+ Terminal::Table.new(title: data['country'].upcase, headings: headings, rows: rows)
30
30
  end
31
31
 
32
32
  def full_country_table(data)
@@ -50,7 +50,7 @@ module Kovid
50
50
  data['critical'],
51
51
  data['casesPerOneMillion']
52
52
  ]
53
- Terminal::Table.new(title: data['country'],
53
+ Terminal::Table.new(title: data['country'].upcase,
54
54
  headings: headings,
55
55
  rows: rows)
56
56
  end
@@ -67,12 +67,12 @@ module Kovid
67
67
 
68
68
  rows = []
69
69
  rows << [state['cases'], state['todayCases'], state['deaths'], state['todayDeaths'], state['recovered'], state['active']]
70
-
70
+
71
71
  puts
72
72
  puts "‼️ Swap value of 'Recovered' for 'Active'. API scraper broke."
73
73
  puts "‼️ So 'Active' is #{state['recovered']} and not #{state['active']}."
74
74
 
75
- Terminal::Table.new(title: state['state'], headings: headings, rows: rows)
75
+ Terminal::Table.new(title: state['state'].upcase, headings: headings, rows: rows)
76
76
  end
77
77
 
78
78
  def compare_countries_table(data)
@@ -126,17 +126,28 @@ module Kovid
126
126
  headings = CASES_DEATHS_RECOVERED
127
127
  rows = [[cases['cases'], cases['deaths'], cases['recovered']]]
128
128
 
129
- Terminal::Table.new(title: 'Total Number of Incidents Worldwide', headings: headings, rows: rows)
129
+ Terminal::Table.new(title: 'Total Number of Incidents Worldwide'.upcase, headings: headings, rows: rows)
130
130
  end
131
131
 
132
- def history(country)
132
+ def history(country, last)
133
133
  headings = DATE_CASES_DEATHS_RECOVERED
134
134
  rows = []
135
- stats = country['timeline'].values.map(&:values).transpose.each do |data|
136
- data.map! { |number| comma_delimit(number) }
137
- end
138
135
 
139
- dates = country['timeline']['cases'].keys
136
+ stats = if last
137
+ country['timeline'].values.map(&:values).transpose.each do |data|
138
+ data.map! { |number| comma_delimit(number) }
139
+ end.last(last.to_i)
140
+ else
141
+ country['timeline'].values.map(&:values).transpose.each do |data|
142
+ data.map! { |number| comma_delimit(number) }
143
+ end
144
+ end
145
+
146
+ dates = if last
147
+ country['timeline']['cases'].keys.last(last.to_i)
148
+ else
149
+ country['timeline']['cases'].keys
150
+ end
140
151
 
141
152
  stats.each_with_index do |val, index|
142
153
  val.unshift(Date.parse(Date.strptime(dates[index], '%m/%d/%y').to_s).strftime('%d %b, %y'))
@@ -144,10 +155,12 @@ module Kovid
144
155
  rows << row
145
156
  end
146
157
 
147
- rows << FOOTER_LINE
148
- rows << DATE_CASES_DEATHS_RECOVERED
158
+ if stats.size > 10
159
+ rows << FOOTER_LINE
160
+ rows << DATE_CASES_DEATHS_RECOVERED
161
+ end
149
162
 
150
- Terminal::Table.new(title: country['standardizedCountryName'].split.map(&:capitalize).join(' '), headings: headings, rows: rows)
163
+ Terminal::Table.new(title: country['standardizedCountryName'].upcase, headings: headings, rows: rows)
151
164
  end
152
165
 
153
166
  private
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.2.4'
4
+ VERSION = '0.2.5'
5
5
  end
data/lib/kovid.rb CHANGED
@@ -36,7 +36,7 @@ module Kovid
36
36
  Kovid::Request.cases
37
37
  end
38
38
 
39
- def history(country)
40
- Kovid::Request.history(country)
39
+ def history(country, last)
40
+ Kovid::Request.history(country, last)
41
41
  end
42
42
  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.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Hayford
@@ -14,58 +14,58 @@ dependencies:
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: terminal-table
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.8'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.8'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: typhoeus
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '1.3'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: colorize
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '0.8'
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'
68
+ version: '0.8'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement