covid19-cli 0.3.0 → 0.4.0

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: 2840c7914dca5a385f3d2211bfd6a04addef08e502bb2c01e50589a219667ab0
4
- data.tar.gz: 5b168484bbceb304a8d40cd3238a846887dc1c4b362ef0872eb50a1dc85cdb24
3
+ metadata.gz: ee64192a0decdfaf8d1a04faea46841ce5bd069479aeba50a6bd6340246a042a
4
+ data.tar.gz: 831fd7debd67f1742792ec458eb18326e132c568cd0e1f46c2ce4c8c5f04271f
5
5
  SHA512:
6
- metadata.gz: '0064308bd1dba8356246751d9e623312962f84d4cadc79b1880f702431fd2850c74cf8a0356dd3b2552d06b44e6fd06b12cf10e8d91224292a898371ff4c10f8'
7
- data.tar.gz: df91a7c53cfe30348e6003acc910758ae1f12ce5b06dbd5949ec6060effb2fed0fc6c2df530e54fc462a420bc11e6058a5a5b4a7a2ec9edf8c7b7c0f34808a1b
6
+ metadata.gz: '05860c64ca75784e598be18d8fb80bf4bf7ad99b3879397944c6aa427a73d99bb0c47917a3573b5720bf1e90f8f102b5662a110b886951da6939c785654f6fb9'
7
+ data.tar.gz: c25e8376746864fb750c38395ebf7de7e6d80fba547bee950b7384238aca2d6f04a28df21007b04ab9141fb429b80aa121eaeeeeeb3c2e51e03745a3fcf8759a
@@ -5,18 +5,29 @@ PATH
5
5
  httparty
6
6
  text-table
7
7
  thor
8
+ tty-pie
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
13
+ coveralls (0.8.23)
14
+ json (>= 1.8, < 3)
15
+ simplecov (~> 0.16.1)
16
+ term-ansicolor (~> 1.3)
17
+ thor (>= 0.19.4, < 2.0)
18
+ tins (~> 1.6)
12
19
  diff-lcs (1.4.4)
20
+ docile (1.3.2)
13
21
  httparty (0.18.1)
14
22
  mime-types (~> 3.0)
15
23
  multi_xml (>= 0.5.2)
24
+ json (2.3.1)
16
25
  mime-types (3.3.1)
17
26
  mime-types-data (~> 3.2015)
18
27
  mime-types-data (3.2020.0512)
19
28
  multi_xml (0.6.0)
29
+ pastel (0.8.0)
30
+ tty-color (~> 0.5)
20
31
  rake (10.5.0)
21
32
  rspec (3.9.0)
22
33
  rspec-core (~> 3.9.0)
@@ -31,14 +42,30 @@ GEM
31
42
  diff-lcs (>= 1.2.0, < 2.0)
32
43
  rspec-support (~> 3.9.0)
33
44
  rspec-support (3.9.3)
45
+ simplecov (0.16.1)
46
+ docile (~> 1.1)
47
+ json (>= 1.8, < 3)
48
+ simplecov-html (~> 0.10.0)
49
+ simplecov-html (0.10.2)
50
+ sync (0.5.0)
51
+ term-ansicolor (1.7.1)
52
+ tins (~> 1.0)
34
53
  text-table (1.2.4)
35
54
  thor (1.0.1)
55
+ tins (1.25.0)
56
+ sync
57
+ tty-color (0.5.1)
58
+ tty-cursor (0.7.1)
59
+ tty-pie (0.4.0)
60
+ pastel (~> 0.8)
61
+ tty-cursor (~> 0.7)
36
62
 
37
63
  PLATFORMS
38
64
  ruby
39
65
 
40
66
  DEPENDENCIES
41
67
  bundler (~> 1.7)
68
+ coveralls
42
69
  covid19-cli!
43
70
  rake (~> 10.0)
44
71
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,4 +1,10 @@
1
- # Covid19::Cli
1
+ # covid19-cli
2
+ ---
3
+ [![Gem Version](http://badge.fury.io/rb/covid19-cli.svg)](http://badge.fury.io/rb/covid19-cli)
4
+ [![Build Status](https://travis-ci.org/TecnoSigma/covid19-cli.svg?branch=master)](https://travis-ci.org/github/TecnoSigma/covid19-cli)
5
+ [![Coverage Status](https://coveralls.io/repos/github/TecnoSigma/covid19-cli/badge.svg?branch=master)](https://coveralls.io/github/TecnoSigma/covid19-cli?branch=master)
6
+ [![Code Climate](https://codeclimate.com/github/TecnoSigma/covid19-cli/badges/gpa.svg)](https://codeclimate.com/github/TecnoSigma/covid19-cli)
7
+ [![GitHub license](https://img.shields.io/apm/l/vim-mode.svg)](LICENSE)
2
8
 
3
9
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/covid19/cli`. To experiment with that code, run `bin/console` for an interactive prompt.
4
10
 
@@ -34,13 +40,30 @@ covid19-cli
34
40
  ```
35
41
  **Output**
36
42
  ```shell
37
- covid19-cli all countries # List all countries data
38
- covid19-cli all_continents # List all continents data
39
- covid19-cli continent CONTINENT_NAME # List continent data
40
- covid19-cli country COUNTRY_NAME # List country data
41
- covid19-cli help [COMMAND] # Describe available commands or one specific command
43
+ covid19-cli all countries # List all countries data
44
+ covid19-cli all_continents # List all continents data
45
+ covid19-cli continent CONTINENT_NAME # List continent data
46
+ covid19-cli country COUNTRY_NAME # List country data
47
+ covid19-cli help [COMMAND] # Describe available commands or one specific command
42
48
  ```
49
+ ---
50
+ **Show available options**
51
+ ```shell
52
+ covid19-cli -h <command_name>
53
+ ```
54
+ **Output**
55
+ ```shell
56
+ Usage:
57
+ covid19-cli <command_name>
58
+
59
+ Options:
60
+ -t, [--table=TABLE]
61
+ -c, [--chart=CHART]
62
+ [--colored=COLORED] <only charts>
43
63
 
64
+ <Command description>
65
+
66
+ ```
44
67
  ---
45
68
 
46
69
  **Get specific continent data in hash format**
@@ -69,6 +92,79 @@ covid19-cli continent africa --table
69
92
 
70
93
  ---
71
94
 
95
+ **Render specific continent data chart**
96
+ ```shell
97
+ covid19-cli continent africa --chart
98
+ ```
99
+ **Output**
100
+ ```shell
101
+ @@@@@@@***xxxxx
102
+ @@@@@@@@@@@**xxxxxxxxxx
103
+ @@@@@@@@@@@@@@@**xxxxxxxxxxxxxx
104
+ @@@@@@@@@@@@@@@@@@**xxxxxxxxxxxxxxxxx
105
+ @@@@@@@@@@@@@@@@@@@@**xxxxxxxxxxxxxxxxxxx
106
+ @@@@@@@@@@@@@@@@@@@@@@**xxxxxxxxxxxxxxxxxxxxx
107
+ @@@@@@@@@@@@@@@@@@@@@@@@**xxxxxxxxxxxxxxxxxxxxxxx
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xxxxxx
124
+ @@@@@@@@@@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
125
+ @@@@@@@@@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxxxxxxxxxxxx
126
+ @@@@@@@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxxxxxxxxxx
127
+ @@@@@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxxxxxxxx
128
+ @@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxxxxxxx
129
+ @@@@@@@@@@@@xxxxxxxxxxxxxxxxxxx
130
+ @@@@@@@@xxxxxxxxxxxxxxx
131
+ @@@xxxxxxxxxxxx
132
+ @@@@@@@********
133
+ @@@@@@@@@@@************
134
+ @@@@@@@@@@@@@@@****************
135
+ @@@@@@@@@@@@@@@@@@*******************
136
+ @@@@@@@@@@@@@@@@@@@@*********************
137
+ @@@@@@@@@@@@@@@@@@@@@@***********************
138
+ @@@@@@@@@@@@@@@@@@@@@@@@*************************
139
+ @@@@@@@@@@@@@@@@@@@@@@@@@**************************
140
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@****************************
141
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@****************************
142
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@*****************************
143
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@******************************
144
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@******************************
145
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@******************************* * todayCases 51.77%
146
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*******************************
147
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@******************************* x todayDeaths 0.55%
148
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*******************************
149
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@******************************* @ todayRecovered 47.68%
150
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@******************************
151
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@******************************
152
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@*****************************
153
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@****************************
154
+ @@@@@@@@@@@@@@@@@@@@@@@@@@x****************************
155
+ @@@@@@@@@@@@@@@@@@@@@@@@x**************************
156
+ @@@@@@@@@@@@@@@@@@@@@@@**************************
157
+ @@@@@@@@@@@@@@@@@@@@@************************
158
+ @@@@@@@@@@@@@@@@@@@**********************
159
+ @@@@@@@@@@@@@@@@@********************
160
+ @@@@@@@@@@@@@@*****************
161
+ @@@@@@@@@x*************
162
+ @@@@@x*********
163
+
164
+ ```
165
+
166
+ ---
167
+
72
168
  **Get specific country data in hash format**
73
169
  ```shell
74
170
  covid19-cli country canada
@@ -95,6 +191,78 @@ covid19-cli country canada --table
95
191
 
96
192
  ---
97
193
 
194
+ **Render specific country data chart**
195
+ ```shell
196
+ covid19-cli country canada --chart
197
+ ```
198
+ **Output**
199
+ ```shell
200
+ @@@@@@@********
201
+ @@@@@@@@@@@********xxxx
202
+ @@@@@@@@@@@@@@@********xxxxxxxx
203
+ @@@@@@@@@@@@@@@@@@*******xxxxxxxxxxxx
204
+ @@@@@@@@@@@@@@@@@@@@*******xxxxxxxxxxxxxx
205
+ @@@@@@@@@@@@@@@@@@@@@@******xxxxxxxxxxxxxxxxx
206
+ @@@@@@@@@@@@@@@@@@@@@@@@******xxxxxxxxxxxxxxxxxxx
207
+ @@@@@@@@@@@@@@@@@@@@@@@@@*****xxxxxxxxxxxxxxxxxxxxx
208
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@****xxxxxxxxxxxxxxxxxxxxxxxx
209
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@****xxxxxxxxxxxxxxxxxxxxxxxx
210
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@***xxxxxxxxxxxxxxxxxxxxxxxxxx
211
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@***xxxxxxxxxxxxxxxxxxxxxxxxxxx
212
+ @@@@@@@@@@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x
230
+ xxxxxxxxxxxxxxx
231
+ @@@@@@@********
232
+ @@@@@@@@@@@************
233
+ @@@@@@@@@@@@@@@****************
234
+ @@@@@@@@@@@@@@@@@@*******************
235
+ @@@@@@@@@@@@@@@@@@@@*********************
236
+ @@@@@@@@@@@@@@@@@@@@@@***********************
237
+ @@@@@@@@@@@@@@@@@@@@@@@@*************************
238
+ @@@@@@@@@@@@@@@@@@@@@@@@@**************************
239
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@****************************
240
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@****************************
241
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@*****************************
242
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@******************************
243
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@******************************
244
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@******************************* * todayCases 44.58%
245
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*******************************
246
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@****************************** x todayDeaths 2.66%
247
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@******************************
248
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@****************************** @ todayRecovered 52.75%
249
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@x****************************
250
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@x****************************
251
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@x***************************
252
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@x*************************
253
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@x*************************
254
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@x***********************
255
+ @@@@@@@@@@@@@@@@@@@@@@@@@@xx*********************
256
+ @@@@@@@@@@@@@@@@@@@@@@@@xx*******************
257
+ @@@@@@@@@@@@@@@@@@@@@@xx*****************
258
+ @@@@@@@@@@@@@@@@@@@@@xx**************
259
+ @@@@@@@@@@@@@@@@@@xx***********
260
+ @@@@@@@@@@@@@@xx*******
261
+ @@@@@@@@@@xxx**
262
+ ```
263
+
264
+ ---
265
+
98
266
  **Get continent general data in hash format**
99
267
  ```shell
100
268
  covid19-cli all_continents
@@ -128,6 +296,46 @@ covid19-cli all_continents
128
296
  | Australia/Oceania | 12 154 | 239 | 133 | 3 | 9 533 | 93 | 2 488 | 28 | 3 672 053 | 89 719.88 |
129
297
  +-------------------+-----------+------------+---------+-------------+-----------+----------------+-----------+----------+-------------+--------------------+
130
298
  ```
299
+ ---
300
+
301
+ **Render all continent data chart**
302
+ ```shell
303
+ covid19-cli all_continents --chart
304
+ ```
305
+ **Output**
306
+ ```shell
307
+ +++%%%%********
308
+ +++++++%%%%************
309
+ +++++++++++%%%%****************
310
+ +++++++++++++++%%%*******************
311
+ +++++++++++++++++%%%*********************
312
+ +++++++++++++++++++%%%***********************
313
+ ++++++++++++++++++++++%%*************************
314
+ +++++++++++++++++++++++%%**************************
315
+ +++++++++++++++++++++++++%%****************************
316
+ ++++++++++++++++++++++++++%**************************** * North America 30.92%
317
+ +++++++++++++++++++++++++++%*****************************
318
+ ++++++++++++++++++++++++++++%****************************** x South America 22.17%
319
+ +++++++++++++++++++++++++++++******************************
320
+ @@@@++++++++++++++++++++++++++******************************* @ Asia 23.09%
321
+ @@@@@@@@@@@@@@@@@+++++++++++++*******************************
322
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@x****************************** + Europe 19.02%
323
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@xxx****************************
324
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@xxxxxx************************* % Africa 4.70%
325
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@xxxxxxxx**********************
326
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@xxxxxxxxxxx******************* # Australia/Oceania 0.09%
327
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@xxxxxxxxxxxxx****************
328
+ @@@@@@@@@@@@@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxx************
329
+ @@@@@@@@@@@@@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxxxx**********
330
+ @@@@@@@@@@@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxxxxxxx*****
331
+ @@@@@@@@@@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxxxxxxxxxx*
332
+ @@@@@@@@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxxxxxxxxx
333
+ @@@@@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxxxxxxxx
334
+ @@@@@@@@@@@@@@@@xxxxxxxxxxxxxxxxxxxxx
335
+ @@@@@@@@@@@@@xxxxxxxxxxxxxxxxxx
336
+ @@@@@@@@@xxxxxxxxxxxxxx
337
+ @@@@@xxxxxxxxxx
338
+ ```
131
339
 
132
340
  ---
133
341
 
@@ -599,6 +807,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
599
807
  * [rspec](https://rubygems.org/gems/rspec)
600
808
  * [text-table](https://rubygems.org/gems/text-table)
601
809
  * [thor](https://rubygems.org/gems/thor)
810
+ * [tty-pie](https://github.com/piotrmurach/tty-pie)
602
811
 
603
812
  ## Contributing
604
813
 
@@ -20,8 +20,11 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_dependency "httparty"
23
- spec.add_dependency "thor"
24
23
  spec.add_dependency "text-table"
24
+ spec.add_dependency "thor"
25
+ spec.add_dependency "tty-pie"
26
+
27
+ spec.add_development_dependency "coveralls"
25
28
  spec.add_development_dependency "bundler", "~> 1.7"
26
29
  spec.add_development_dependency "rake", "~> 10.0"
27
30
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -1,6 +1,7 @@
1
1
  require 'thor'
2
2
  require_relative 'services/covid19_data'
3
3
  require_relative 'decorators/table'
4
+ require_relative 'decorators/chart'
4
5
 
5
6
  module Covid19
6
7
  class Client < Thor
@@ -9,41 +10,81 @@ module Covid19
9
10
  end
10
11
 
11
12
  desc 'all_continents', 'List all continents data'
12
- option :table, required: false
13
+ option :table, aliases: '-t', required: false
14
+ option :chart, aliases: '-c', required: false
15
+ option :colored, required: false
13
16
  def all_continents
14
17
  locality = Covid19::Decorators::Table::LOCALITY[:continent]
15
18
  result = Covid19::Services::Covid19Data.all_continents
16
19
 
17
- puts options[:table] ?
18
- Covid19::Decorators::Table.create(data: result, locality: locality) :
19
- result
20
+ puts result if options.empty?
21
+ render_table(data: result, locality: locality) if options[:table]
22
+ render_chart(data: result,
23
+ type: Covid19::Decorators::Chart::TYPES[:all_continent_general_data],
24
+ colored: options[:colored]) if options[:chart]
20
25
  end
21
26
 
22
27
  desc 'all countries', 'List all countries data'
23
- option :table, required: false
28
+ option :table, aliases: '-t', required: false
24
29
  def all_countries
25
30
  locality = Covid19::Decorators::Table::LOCALITY[:country]
26
31
  result = Covid19::Services::Covid19Data.all_countries
27
-
28
- puts options[:table] ?
29
- Covid19::Decorators::Table.create(data: result, locality: locality):
30
- result
32
+
33
+ puts result if options.empty?
34
+ render_table(data: result, locality: locality) if options[:table]
31
35
  end
32
36
 
33
37
  desc 'continent CONTINENT_NAME', 'List continent data'
34
- option :table, required: false
38
+ option :table, aliases: '-t', required: false
39
+ option :chart, aliases: '-c', required: false
40
+ option :colored, required: false
35
41
  def continent(continent_name)
36
42
  result = Covid19::Services::Covid19Data.continent(continent_name)
37
43
 
38
- puts options[:table] ? Covid19::Decorators::Table.create(data: result) : result
44
+ puts result if options.empty?
45
+ render_table(data: result) if options[:table]
46
+
47
+ if options[:chart]
48
+ render_chart(data: result,
49
+ type: Covid19::Decorators::Chart::TYPES[:continent_general_data],
50
+ colored: options[:colored])
51
+ render_chart(data: result,
52
+ type: Covid19::Decorators::Chart::TYPES[:continent_diary_data],
53
+ colored: options[:colored])
54
+ end
39
55
  end
40
56
 
41
57
  desc 'country COUNTRY_NAME', 'List country data'
42
58
  option :table, required: false
59
+ option :table, aliases: '-t', required: false
60
+ option :chart, aliases: '-c', required: false
61
+ option :colored, required: false
43
62
  def country(country_name)
44
63
  result = Covid19::Services::Covid19Data.country(country_name)
45
64
 
46
- puts options[:table] ? Covid19::Decorators::Table.create(data: result) : result
65
+ puts result if options.empty?
66
+
67
+ render_table(data: result) if options[:table]
68
+
69
+ if options[:chart]
70
+ render_chart(data: result,
71
+ type: Covid19::Decorators::Chart::TYPES[:country_general_data],
72
+ colored: options[:colored])
73
+ render_chart(data: result,
74
+ type: Covid19::Decorators::Chart::TYPES[:country_diary_data],
75
+ colored: options[:colored])
76
+ end
47
77
  end
78
+
79
+ private
80
+
81
+ def render_table(data:, locality: nil)
82
+ puts Covid19::Decorators::Table.create(data: data, locality: locality)
83
+ end
84
+
85
+ def render_chart(data:, type:, colored:)
86
+ puts Covid19::Decorators::Chart
87
+ .create_pie(data: data, type: type, colored: options[:colored])
88
+ end
48
89
  end
49
90
  end
@@ -0,0 +1,80 @@
1
+ require 'tty-pie'
2
+
3
+ module Covid19
4
+ module Decorators
5
+ class Chart
6
+ TYPES = { all_continent_general_data: 'all_continent_general_data',
7
+ continent_general_data: 'continent_general_data',
8
+ continent_diary_data: 'continent_diary_data',
9
+ country_general_data: 'country_general_data',
10
+ country_diary_data: 'country_diary_data' }
11
+ DEFAULT_FILL = 'Ø'
12
+ SIZE = 15
13
+ FILLS = %w(* x @ + % #)
14
+ COLORS = %i(bright_yellow
15
+ bright_green
16
+ bright_magenta
17
+ bright_cyan
18
+ bright_red
19
+ bright_white)
20
+ GENERAL_TOTALS = %w(deaths
21
+ recovered
22
+ active)
23
+ DIARY_TOTALS = %w(todayCases
24
+ todayDeaths
25
+ todayRecovered)
26
+
27
+ def self.create_pie(data:, type:, colored: nil)
28
+ pie_data = case type
29
+ when TYPES[:all_continent_general_data]
30
+ mount_all_continent_general_data(data)
31
+ when TYPES[:continent_general_data]
32
+ mount_general_data(data)
33
+ when TYPES[:country_general_data]
34
+ mount_general_data(data)
35
+ when TYPES[:continent_diary_data]
36
+ mount_diary_data(data)
37
+ when TYPES[:country_diary_data]
38
+ mount_diary_data(data)
39
+ else
40
+ raise ArgumentError.new('Error in chart plot!')
41
+ end
42
+
43
+ formatted_chart = colored ? add_color(pie_data) : add_fill(pie_data)
44
+
45
+ TTY::Pie.new(data: formatted_chart, radius: SIZE)
46
+ end
47
+
48
+ def self.add_color(pie_data)
49
+ pie_data.each_with_index {|hash, index| hash.merge!({fill: DEFAULT_FILL, color: COLORS[index]})}
50
+ end
51
+
52
+ def self.add_fill(pie_data)
53
+ pie_data.each_with_index {|hash, index| hash.merge!({fill: FILLS[index]})}
54
+ end
55
+
56
+ def self.mount_all_continent_general_data(data)
57
+ data.map {|occurrency| {name: occurrency['continent'], value: occurrency['cases']}}
58
+ end
59
+
60
+ def self.mount_general_data(data)
61
+ data
62
+ .select { |key, value| GENERAL_TOTALS.include?(key) }
63
+ .map { |occurrency| {name: occurrency.first, value: occurrency.last} }
64
+ end
65
+
66
+ def self.mount_diary_data(data)
67
+ data
68
+ .select { |key, value| DIARY_TOTALS.include?(key) }
69
+ .map { |occurrency| {name: occurrency.first, value: occurrency.last} }
70
+ end
71
+
72
+ private_class_method :add_color,
73
+ :add_fill,
74
+ :mount_all_continent_general_data,
75
+ :mount_general_data,
76
+ :mount_diary_data
77
+
78
+ end
79
+ end
80
+ end
@@ -1,3 +1,3 @@
1
1
  module Covid19
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,45 @@
1
+ require_relative '../../../../lib/covid19/decorators/chart'
2
+
3
+ RSpec.describe 'Covid19::Decorators::Chart' do
4
+ describe '.create_pie' do
5
+ it 'returns continent general data in chart format' do
6
+ data = {"updated"=>1594917732234, "cases"=>3186881, "todayCases"=>55997, "deaths"=>75141, "todayDeaths"=>1254, "recovered"=>2232648, "todayRecovered"=>30503, "active"=>879092, "critical"=>19976, "casesPerOneMillion"=>691.15, "deathsPerOneMillion"=>16.3, "tests"=>136692398, "testsPerOneMillion"=>29645.11, "population"=>4610959075, "continent"=>"Asia", "activePerOneMillion"=>190.65, "recoveredPerOneMillion"=>484.2, "criticalPerOneMillion"=>4.33, "continentInfo"=>{"lat"=>23.7027273, "long"=>62.3750637}, "countries"=>["Afghanistan", "Armenia", "Azerbaijan", "Bahrain", "Bangladesh", "Bhutan", "Brunei", "Cambodia", "China", "Cyprus", "Georgia", "Hong Kong", "India", "Indonesia", "Iran", "Iraq", "Israel", "Japan", "Jordan", "Kazakhstan", "Kuwait", "Kyrgyzstan", "Lao People's Democratic Republic", "Lebanon", "Macao", "Malaysia", "Maldives", "Mongolia", "Myanmar", "Nepal", "Oman", "Pakistan", "Palestine", "Philippines", "Qatar", "S. Korea", "Saudi Arabia", "Singapore", "Sri Lanka", "Syrian Arab Republic", "Taiwan", "Tajikistan", "Thailand", "Timor-Leste", "Turkey", "UAE", "Uzbekistan", "Vietnam", "Yemen"]}
7
+
8
+ result = Covid19::Decorators::Chart.create_pie(data: data, type: 'continent_general_data', colored: 'colored')
9
+
10
+ expect(result).not_to be_nil
11
+ end
12
+
13
+ it 'returns country general data in chart format' do
14
+ data = {"updated"=>1594917731967, "country"=>"Brazil", "countryInfo"=>{"_id"=>76, "iso2"=>"BR", "iso3"=>"BRA", "lat"=>-10, "long"=>-55, "flag"=>"https://disease.sh/assets/img/flags/br.png"}, "cases"=>1978236, "todayCases"=>7327, "deaths"=>75697, "todayDeaths"=>174, "recovered"=>1366775, "todayRecovered"=>111211, "active"=>535764, "critical"=>8318, "casesPerOneMillion"=>9304, "deathsPerOneMillion"=>356, "tests"=>4911063, "testsPerOneMillion"=>23098, "population"=>212620008, "continent"=>"South America", "oneCasePerPeople"=>107, "oneDeathPerPeople"=>2809, "oneTestPerPeople"=>43, "activePerOneMillion"=>2519.82, "recoveredPerOneMillion"=>6428.25, "criticalPerOneMillion"=>39.12}
15
+
16
+ result = Covid19::Decorators::Chart.create_pie(data: data, type: 'country_general_data', colored: 'colored')
17
+
18
+ expect(result).not_to be_nil
19
+ end
20
+
21
+ it 'returns continent diary data in chart format' do
22
+ data = {"updated"=>1594917732234, "cases"=>3186881, "todayCases"=>55997, "deaths"=>75141, "todayDeaths"=>1254, "recovered"=>2232648, "todayRecovered"=>30503, "active"=>879092, "critical"=>19976, "casesPerOneMillion"=>691.15, "deathsPerOneMillion"=>16.3, "tests"=>136692398, "testsPerOneMillion"=>29645.11, "population"=>4610959075, "continent"=>"Asia", "activePerOneMillion"=>190.65, "recoveredPerOneMillion"=>484.2, "criticalPerOneMillion"=>4.33, "continentInfo"=>{"lat"=>23.7027273, "long"=>62.3750637}, "countries"=>["Afghanistan", "Armenia", "Azerbaijan", "Bahrain", "Bangladesh", "Bhutan", "Brunei", "Cambodia", "China", "Cyprus", "Georgia", "Hong Kong", "India", "Indonesia", "Iran", "Iraq", "Israel", "Japan", "Jordan", "Kazakhstan", "Kuwait", "Kyrgyzstan", "Lao People's Democratic Republic", "Lebanon", "Macao", "Malaysia", "Maldives", "Mongolia", "Myanmar", "Nepal", "Oman", "Pakistan", "Palestine", "Philippines", "Qatar", "S. Korea", "Saudi Arabia", "Singapore", "Sri Lanka", "Syrian Arab Republic", "Taiwan", "Tajikistan", "Thailand", "Timor-Leste", "Turkey", "UAE", "Uzbekistan", "Vietnam", "Yemen"]}
23
+
24
+ result = Covid19::Decorators::Chart.create_pie(data: data, type: 'continent_diary_data', colored: 'colored')
25
+
26
+ expect(result).not_to be_nil
27
+ end
28
+
29
+ it 'returns country diary data in chart format' do
30
+ data = {"updated"=>1594917731967, "country"=>"Brazil", "countryInfo"=>{"_id"=>76, "iso2"=>"BR", "iso3"=>"BRA", "lat"=>-10, "long"=>-55, "flag"=>"https://disease.sh/assets/img/flags/br.png"}, "cases"=>1978236, "todayCases"=>7327, "deaths"=>75697, "todayDeaths"=>174, "recovered"=>1366775, "todayRecovered"=>111211, "active"=>535764, "critical"=>8318, "casesPerOneMillion"=>9304, "deathsPerOneMillion"=>356, "tests"=>4911063, "testsPerOneMillion"=>23098, "population"=>212620008, "continent"=>"South America", "oneCasePerPeople"=>107, "oneDeathPerPeople"=>2809, "oneTestPerPeople"=>43, "activePerOneMillion"=>2519.82, "recoveredPerOneMillion"=>6428.25, "criticalPerOneMillion"=>39.12}
31
+
32
+ result = Covid19::Decorators::Chart.create_pie(data: data, type: 'country_diary_data', colored: 'colored')
33
+
34
+ expect(result).not_to be_nil
35
+ end
36
+
37
+ it 'returns all continent general data in chart format' do
38
+ data = [{"updated"=>1594917732234, "cases"=>3186881, "todayCases"=>55997, "deaths"=>75141, "todayDeaths"=>1254, "recovered"=>2232648, "todayRecovered"=>30503, "active"=>879092, "critical"=>19976, "casesPerOneMillion"=>691.15, "deathsPerOneMillion"=>16.3, "tests"=>136692398, "testsPerOneMillion"=>29645.11, "population"=>4610959075, "continent"=>"Asia", "activePerOneMillion"=>190.65, "recoveredPerOneMillion"=>484.2, "criticalPerOneMillion"=>4.33, "continentInfo"=>{"lat"=>23.7027273, "long"=>62.3750637}, "countries"=>["Afghanistan", "Armenia", "Azerbaijan", "Bahrain", "Bangladesh", "Bhutan", "Brunei", "Cambodia", "China", "Cyprus", "Georgia", "Hong Kong", "India", "Indonesia", "Iran", "Iraq", "Israel", "Japan", "Jordan", "Kazakhstan", "Kuwait", "Kyrgyzstan", "Lao People's Democratic Republic", "Lebanon", "Macao", "Malaysia", "Maldives", "Mongolia", "Myanmar", "Nepal", "Oman", "Pakistan", "Palestine", "Philippines", "Qatar", "S. Korea", "Saudi Arabia", "Singapore", "Sri Lanka", "Syrian Arab Republic", "Taiwan", "Tajikistan", "Thailand", "Timor-Leste", "Turkey", "UAE", "Uzbekistan", "Vietnam", "Yemen"]}]
39
+
40
+ result = Covid19::Decorators::Chart.create_pie(data: data, type: 'all_continent_general_data', colored: 'colored')
41
+
42
+ expect(result).not_to be_nil
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  RSpec.describe Covid19::Client do
2
2
  it "has version latest number" do
3
- expect(Covid19::VERSION).to eq('0.3.0')
3
+ expect(Covid19::VERSION).to eq('0.4.0')
4
4
  end
5
5
  end
@@ -1,5 +1,8 @@
1
1
  require "bundler/setup"
2
2
  require "covid19/client"
3
+ require "coveralls"
4
+
5
+ Coveralls.wear!
3
6
 
4
7
  RSpec.configure do |config|
5
8
  # Enable flags like --only-failures and --next-failure
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: covid19-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Carlos Martins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: text-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: thor
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +53,7 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: text-table
56
+ name: tty-pie
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: bundler
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -117,9 +145,11 @@ files:
117
145
  - covid19-cli.gemspec
118
146
  - exe/covid19-cli
119
147
  - lib/covid19/client.rb
148
+ - lib/covid19/decorators/chart.rb
120
149
  - lib/covid19/decorators/table.rb
121
150
  - lib/covid19/services/covid19_data.rb
122
151
  - lib/covid19/version.rb
152
+ - spec/lib/covid19/decorators/chart_spec.rb
123
153
  - spec/lib/covid19/decorators/table_spec.rb
124
154
  - spec/lib/covid19/services/covid19_data_spec.rb
125
155
  - spec/lib/covid19/version_spec.rb