kovid 0.2.4 → 0.3.0
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 +4 -4
 - data/Gemfile.lock +7 -7
 - data/README.md +15 -11
 - data/kovid.gemspec +4 -4
 - data/lib/kovid.rb +2 -2
 - data/lib/kovid/cli.rb +16 -4
 - data/lib/kovid/painter.rb +5 -5
 - data/lib/kovid/request.rb +7 -9
 - data/lib/kovid/tablelize.rb +68 -31
 - data/lib/kovid/version.rb +1 -1
 - metadata +19 -19
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: fa7abbc0a4d9eca2bbc865fd6740fdf7ae611ec5290cf96e6ce28248982f2f00
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 51ad886114e16c076fca34b96e4bd92c30022eb0a5fcff2e4a20eb067f688e8b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 93ac6304f8fcbf01b071e0be5dbf39d8a717d2fb9449f5851abe60f2ece6b17d541828817cbe42ede1cec787018c32f000a410287ee5ed3987d74a41ddcf43f3
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 5cbe6f55009cb9a8af32a16a98739cf6df669218e903684232e86a58372c29fdd70c5d3ae2102228449c4e85157e58f02c31971a9f158375e17ee06cd389864f
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -1,11 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            PATH
         
     | 
| 
       2 
2 
     | 
    
         
             
              remote: .
         
     | 
| 
       3 
3 
     | 
    
         
             
              specs:
         
     | 
| 
       4 
     | 
    
         
            -
                kovid (0. 
     | 
| 
       5 
     | 
    
         
            -
                   
     | 
| 
       6 
     | 
    
         
            -
                  terminal-table
         
     | 
| 
       7 
     | 
    
         
            -
                  thor
         
     | 
| 
       8 
     | 
    
         
            -
                  typhoeus
         
     | 
| 
      
 4 
     | 
    
         
            +
                kovid (0.3.0)
         
     | 
| 
      
 5 
     | 
    
         
            +
                  rainbow (~> 3.0)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  terminal-table (~> 1.8)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  thor (~> 1.0)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  typhoeus (~> 1.3)
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            GEM
         
     | 
| 
       11 
11 
     | 
    
         
             
              remote: https://rubygems.org/
         
     | 
| 
         @@ -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. 
     | 
| 
      
 92 
     | 
    
         
            +
               2.1.4
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -4,7 +4,8 @@ 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
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.
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
            Code contribution and ideas welcome.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
            ## ⚙️ Installation
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
         @@ -14,30 +15,33 @@ Before installing: 
     | 
|
| 
       14 
15 
     | 
    
         | 
| 
       15 
16 
     | 
    
         
             
            ✌️ Run `gem install kovid`
         
     | 
| 
       16 
17 
     | 
    
         | 
| 
      
 18 
     | 
    
         
            +
            UPDATE often with `gem update kovid`
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
       17 
20 
     | 
    
         | 
| 
       18 
21 
     | 
    
         | 
| 
       19 
22 
     | 
    
         
             
            ## ⚒️ Usage
         
     | 
| 
       20 
23 
     | 
    
         | 
| 
       21 
24 
     | 
    
         
             
            You can run `kovid --help` to see the full list of available commands.
         
     | 
| 
       22 
25 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
            **NOTE:** If you find it irritating to have to type `kovid state  
     | 
| 
      
 26 
     | 
    
         
            +
            **NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
         
     | 
| 
       24 
27 
     | 
    
         | 
| 
       25 
28 
     | 
    
         
             
            #### Commands Overview
         
     | 
| 
       26 
29 
     | 
    
         
             
            😷 **Fetching**
         
     | 
| 
       27 
     | 
    
         
            -
            * `kovid check  
     | 
| 
       28 
     | 
    
         
            -
            * `kovid check  
     | 
| 
      
 30 
     | 
    
         
            +
            * `kovid check COUNTRY` (`kovid country COUNTRY` works as well)
         
     | 
| 
      
 31 
     | 
    
         
            +
            * `kovid check COUNTRY -f` OR `kovid check COUNTRY --full`
         
     | 
| 
       29 
32 
     | 
    
         | 
| 
       30 
33 
     | 
    
         
             
            🇺🇸You can fetch US state-specific data 🇺🇸
         
     | 
| 
       31 
     | 
    
         
            -
            * `kovid state  
     | 
| 
      
 34 
     | 
    
         
            +
            * `kovid state STATE` OR `kovid state "STATE WITH SPACES"`
         
     | 
| 
       32 
35 
     | 
    
         | 
| 
       33 
36 
     | 
    
         
             
            😷 **Comparing**
         
     | 
| 
       34 
     | 
    
         
            -
            * `kovid compare  
     | 
| 
       35 
     | 
    
         
            -
            * `kovid compare  
     | 
| 
      
 37 
     | 
    
         
            +
            * `kovid compare COUNTRYA COUNTRYB` (sorts by cases DESC)
         
     | 
| 
      
 38 
     | 
    
         
            +
            * `kovid compare COUNTRYA COUNTRYB -f` OR `kovid compare COUNTRYA COUNTRYB --full` (sorts by cases DESC)
         
     | 
| 
       36 
39 
     | 
    
         | 
| 
       37 
40 
     | 
    
         
             
            You can compare as many countries as you want.
         
     | 
| 
       38 
41 
     | 
    
         | 
| 
       39 
42 
     | 
    
         
             
            😷 **History**
         
     | 
| 
       40 
     | 
    
         
            -
            * `kovid history  
     | 
| 
      
 43 
     | 
    
         
            +
            * `kovid history COUNTRY` (full history)
         
     | 
| 
      
 44 
     | 
    
         
            +
            * `kovid history COUNTRY N` (history in the last N days)
         
     | 
| 
       41 
45 
     | 
    
         | 
| 
       42 
46 
     | 
    
         
             
            😷 **Total figures**
         
     | 
| 
       43 
47 
     | 
    
         
             
            * `kovid cases`
         
     | 
| 
         @@ -73,15 +77,15 @@ To compare a countries stats with a full table: 
     | 
|
| 
       73 
77 
     | 
    
         | 
| 
       74 
78 
     | 
    
         
             
            To fetch state-specific data run:
         
     | 
| 
       75 
79 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
            `kovid state colorado`
         
     | 
| 
      
 80 
     | 
    
         
            +
            `kovid state colorado` OR `kovid state "north carolina"`
         
     | 
| 
       77 
81 
     | 
    
         | 
| 
       78 
82 
     | 
    
         
             
            
         
     | 
| 
       79 
83 
     | 
    
         | 
| 
       80 
84 
     | 
    
         
             
            You can check historical statistics by running
         
     | 
| 
       81 
85 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
            `kovid history  
     | 
| 
      
 86 
     | 
    
         
            +
            `kovid history italy 7` eg:
         
     | 
| 
       83 
87 
     | 
    
         | 
| 
       84 
     | 
    
         
            -
            
         
     | 
| 
       85 
89 
     | 
    
         | 
| 
       86 
90 
     | 
    
         
             
            To check for total figures:
         
     | 
| 
       87 
91 
     | 
    
         | 
    
        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 " 
     | 
| 
      
 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 "rainbow", "~> 3.0"
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
53 
     | 
    
         
             
              spec.add_development_dependency "pry"
         
     | 
| 
       54 
54 
     | 
    
         
             
              spec.add_development_dependency "cucumber"
         
     | 
    
        data/lib/kovid.rb
    CHANGED
    
    
    
        data/lib/kovid/cli.rb
    CHANGED
    
    | 
         @@ -21,8 +21,16 @@ module Kovid 
     | 
|
| 
       21 
21 
     | 
    
         
             
                    puts Kovid.country(name)
         
     | 
| 
       22 
22 
     | 
    
         
             
                  end
         
     | 
| 
       23 
23 
     | 
    
         
             
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
       24 
25 
     | 
    
         
             
                desc 'country COUNTRY or country "COUNTRY NAME"', 'Returns reported data on provided country. eg: "kovid country "hong kong".'
         
     | 
| 
       25 
     | 
    
         
            -
                 
     | 
| 
      
 26 
     | 
    
         
            +
                method_option :full, aliases: '-f'
         
     | 
| 
      
 27 
     | 
    
         
            +
                def country(name)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  if options[:full]
         
     | 
| 
      
 29 
     | 
    
         
            +
                    puts Kovid.country_full(name)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  else
         
     | 
| 
      
 31 
     | 
    
         
            +
                    puts Kovid.country(name)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
       26 
34 
     | 
    
         | 
| 
       27 
35 
     | 
    
         
             
                desc 'state STATE', 'Return reported data on provided state.'
         
     | 
| 
       28 
36 
     | 
    
         
             
                def state(state)
         
     | 
| 
         @@ -43,9 +51,13 @@ module Kovid 
     | 
|
| 
       43 
51 
     | 
    
         
             
                  puts Kovid.cases
         
     | 
| 
       44 
52 
     | 
    
         
             
                end
         
     | 
| 
       45 
53 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
                desc 'history COUNTRY', 'Return history of incidents of COUNTRY'
         
     | 
| 
       47 
     | 
    
         
            -
                def history( 
     | 
| 
       48 
     | 
    
         
            -
                   
     | 
| 
      
 54 
     | 
    
         
            +
                desc 'history COUNTRY or history COUNTRY N', 'Return history of incidents of COUNTRY (in the last N days)'
         
     | 
| 
      
 55 
     | 
    
         
            +
                def history(*params)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  if params.size == 2
         
     | 
| 
      
 57 
     | 
    
         
            +
                    puts Kovid.history(params.first, params.last)
         
     | 
| 
      
 58 
     | 
    
         
            +
                  else
         
     | 
| 
      
 59 
     | 
    
         
            +
                    puts Kovid.history(params.first, nil)
         
     | 
| 
      
 60 
     | 
    
         
            +
                  end
         
     | 
| 
       49 
61 
     | 
    
         
             
                end
         
     | 
| 
       50 
62 
     | 
    
         
             
              end
         
     | 
| 
       51 
63 
     | 
    
         
             
            end
         
     | 
    
        data/lib/kovid/painter.rb
    CHANGED
    
    | 
         @@ -1,21 +1,21 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            require ' 
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rainbow'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            class String
         
     | 
| 
       6 
6 
     | 
    
         
             
              def paint_white
         
     | 
| 
       7 
     | 
    
         
            -
                 
     | 
| 
      
 7 
     | 
    
         
            +
                Rainbow(self).white.bg(:black).bold
         
     | 
| 
       8 
8 
     | 
    
         
             
              end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              def paint_red
         
     | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
      
 11 
     | 
    
         
            +
                Rainbow(self).red.bg(:black).bold
         
     | 
| 
       12 
12 
     | 
    
         
             
              end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
              def paint_green
         
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
      
 15 
     | 
    
         
            +
                Rainbow(self).green.bg(:black).bold
         
     | 
| 
       16 
16 
     | 
    
         
             
              end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
              def paint_yellow
         
     | 
| 
       19 
     | 
    
         
            -
                 
     | 
| 
      
 19 
     | 
    
         
            +
                Rainbow(self).yellow.bg(:black).bold
         
     | 
| 
       20 
20 
     | 
    
         
             
              end
         
     | 
| 
       21 
21 
     | 
    
         
             
            end
         
     | 
    
        data/lib/kovid/request.rb
    CHANGED
    
    | 
         @@ -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)
         
     | 
| 
         @@ -48,17 +49,17 @@ module Kovid 
     | 
|
| 
       48 
49 
     | 
    
         
             
                    Kovid::Tablelize.cases(response)
         
     | 
| 
       49 
50 
     | 
    
         
             
                  end
         
     | 
| 
       50 
51 
     | 
    
         | 
| 
       51 
     | 
    
         
            -
                  def history(country)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  def history(country, last)
         
     | 
| 
       52 
53 
     | 
    
         
             
                    history_path = UriBuilder.new('/historical').url
         
     | 
| 
       53 
54 
     | 
    
         
             
                    response ||= JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
         
     | 
| 
       54 
55 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
                    Kovid::Tablelize.history(response)
         
     | 
| 
      
 56 
     | 
    
         
            +
                    Kovid::Tablelize.history(response, last)
         
     | 
| 
       56 
57 
     | 
    
         
             
                  end
         
     | 
| 
       57 
58 
     | 
    
         | 
| 
       58 
59 
     | 
    
         
             
                  private
         
     | 
| 
       59 
60 
     | 
    
         | 
| 
       60 
61 
     | 
    
         
             
                  def no_case_in(country)
         
     | 
| 
       61 
     | 
    
         
            -
                    rows = [['No reported cases OR  
     | 
| 
      
 62 
     | 
    
         
            +
                    rows = [['No reported cases OR wrong spelling of country/state!']]
         
     | 
| 
       62 
63 
     | 
    
         
             
                    Terminal::Table.new headings: ["You checked: #{country.capitalize}"], rows: rows
         
     | 
| 
       63 
64 
     | 
    
         
             
                  end
         
     | 
| 
       64 
65 
     | 
    
         | 
| 
         @@ -73,20 +74,17 @@ module Kovid 
     | 
|
| 
       73 
74 
     | 
    
         
             
                  end
         
     | 
| 
       74 
75 
     | 
    
         | 
| 
       75 
76 
     | 
    
         
             
                  def fetch_country(country_name)
         
     | 
| 
       76 
     | 
    
         
            -
                     
     | 
| 
      
 77 
     | 
    
         
            +
                    country_url = COUNTRIES_PATH + "/#{country_name}"
         
     | 
| 
       77 
78 
     | 
    
         | 
| 
       78 
     | 
    
         
            -
                    JSON.parse(Typhoeus.get( 
     | 
| 
      
 79 
     | 
    
         
            +
                    JSON.parse(Typhoeus.get(country_url, cache_ttl: 900).response_body)
         
     | 
| 
       79 
80 
     | 
    
         
             
                  end
         
     | 
| 
       80 
81 
     | 
    
         | 
| 
       81 
82 
     | 
    
         
             
                  def fetch_state(state)
         
     | 
| 
       82 
     | 
    
         
            -
                     
     | 
| 
       83 
     | 
    
         
            -
                    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)
         
     | 
| 
       84 
84 
     | 
    
         | 
| 
       85 
85 
     | 
    
         
             
                    states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
         
     | 
| 
       86 
86 
     | 
    
         
             
                  end
         
     | 
| 
       87 
87 
     | 
    
         | 
| 
       88 
     | 
    
         
            -
                  private
         
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
88 
     | 
    
         
             
                  def capitalize_words(string)
         
     | 
| 
       91 
89 
     | 
    
         
             
                    string.split.map(&:capitalize).join(' ')
         
     | 
| 
       92 
90 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/kovid/tablelize.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
                     
     | 
| 
      
 30 
     | 
    
         
            +
                    if iso = data['countryInfo']['iso2']
         
     | 
| 
      
 31 
     | 
    
         
            +
                      Terminal::Table.new(title: "#{data['country'].upcase}", 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 
     | 
    
         
             
                    ]
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
      
 66 
     | 
    
         
            +
                      Terminal::Table.new(title: data['country'].upcase,
         
     | 
| 
      
 67 
     | 
    
         
            +
                                          headings: headings,
         
     | 
| 
      
 68 
     | 
    
         
            +
                                          rows: rows)
         
     | 
| 
      
 69 
     | 
    
         
            +
                    end
         
     | 
| 
      
 70 
     | 
    
         
            +
                    # TODO: Rafactor this
         
     | 
| 
       56 
71 
     | 
    
         
             
                  end
         
     | 
| 
       57 
72 
     | 
    
         | 
| 
       58 
73 
     | 
    
         
             
                  def full_state_table(state)
         
     | 
| 
         @@ -61,18 +76,13 @@ 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[' 
     | 
| 
       70 
     | 
    
         
            -
                    
         
     | 
| 
       71 
     | 
    
         
            -
                    puts
         
     | 
| 
       72 
     | 
    
         
            -
                    puts "‼️  Swap value of 'Recovered' for 'Active'. API scraper broke."
         
     | 
| 
       73 
     | 
    
         
            -
                    puts "‼️  So 'Active' is #{state['recovered']} and not #{state['active']}."
         
     | 
| 
      
 83 
     | 
    
         
            +
                    rows << [state['cases'], check_if_positve(state['todayCases']), state['deaths'], check_if_positve(state['todayDeaths']), state['active']]
         
     | 
| 
       74 
84 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
                    Terminal::Table.new(title: state['state'], headings: headings, rows: rows)
         
     | 
| 
      
 85 
     | 
    
         
            +
                    Terminal::Table.new(title: state['state'].upcase, headings: headings, rows: rows)
         
     | 
| 
       76 
86 
     | 
    
         
             
                  end
         
     | 
| 
       77 
87 
     | 
    
         | 
| 
       78 
88 
     | 
    
         
             
                  def compare_countries_table(data)
         
     | 
| 
         @@ -86,7 +96,7 @@ module Kovid 
     | 
|
| 
       86 
96 
     | 
    
         
             
                    rows = []
         
     | 
| 
       87 
97 
     | 
    
         | 
| 
       88 
98 
     | 
    
         
             
                    data.each do |country|
         
     | 
| 
       89 
     | 
    
         
            -
                      rows << [country['country'], country['cases'], country['deaths'], country['recovered']]
         
     | 
| 
      
 99 
     | 
    
         
            +
                      rows << [country['country'].upcase, comma_delimit(country['cases']), comma_delimit(country['deaths']), comma_delimit(country['recovered'])]
         
     | 
| 
       90 
100 
     | 
    
         
             
                    end
         
     | 
| 
       91 
101 
     | 
    
         | 
| 
       92 
102 
     | 
    
         
             
                    Terminal::Table.new(headings: headings, rows: rows)
         
     | 
| 
         @@ -109,13 +119,13 @@ module Kovid 
     | 
|
| 
       109 
119 
     | 
    
         
             
                    data.each do |country|
         
     | 
| 
       110 
120 
     | 
    
         
             
                      rows << [
         
     | 
| 
       111 
121 
     | 
    
         
             
                        country['country'],
         
     | 
| 
       112 
     | 
    
         
            -
                        country['cases'],
         
     | 
| 
       113 
     | 
    
         
            -
                        country['deaths'],
         
     | 
| 
       114 
     | 
    
         
            -
                        country['recovered'],
         
     | 
| 
       115 
     | 
    
         
            -
                        country['todayCases'],
         
     | 
| 
       116 
     | 
    
         
            -
                        country['todayDeaths'],
         
     | 
| 
       117 
     | 
    
         
            -
                        country['critical'],
         
     | 
| 
       118 
     | 
    
         
            -
                        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'])
         
     | 
| 
       119 
129 
     | 
    
         
             
                      ]
         
     | 
| 
       120 
130 
     | 
    
         
             
                    end
         
     | 
| 
       121 
131 
     | 
    
         | 
| 
         @@ -124,19 +134,36 @@ module Kovid 
     | 
|
| 
       124 
134 
     | 
    
         | 
| 
       125 
135 
     | 
    
         
             
                  def cases(cases)
         
     | 
| 
       126 
136 
     | 
    
         
             
                    headings = CASES_DEATHS_RECOVERED
         
     | 
| 
       127 
     | 
    
         
            -
                    rows = [ 
     | 
| 
      
 137 
     | 
    
         
            +
                    rows = [
         
     | 
| 
      
 138 
     | 
    
         
            +
                      [
         
     | 
| 
      
 139 
     | 
    
         
            +
                        comma_delimit(cases['cases']),
         
     | 
| 
      
 140 
     | 
    
         
            +
                        comma_delimit(cases['deaths']),
         
     | 
| 
      
 141 
     | 
    
         
            +
                          comma_delimit(cases['recovered'])
         
     | 
| 
      
 142 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 143 
     | 
    
         
            +
                    ]
         
     | 
| 
       128 
144 
     | 
    
         | 
| 
       129 
     | 
    
         
            -
                    Terminal::Table.new(title: 'Total Number of Incidents Worldwide', headings: headings, rows: rows)
         
     | 
| 
      
 145 
     | 
    
         
            +
                    Terminal::Table.new(title: 'Total Number of Incidents Worldwide'.upcase, headings: headings, rows: rows)
         
     | 
| 
       130 
146 
     | 
    
         
             
                  end
         
     | 
| 
       131 
147 
     | 
    
         | 
| 
       132 
     | 
    
         
            -
                  def history(country)
         
     | 
| 
      
 148 
     | 
    
         
            +
                  def history(country, last)
         
     | 
| 
       133 
149 
     | 
    
         
             
                    headings = DATE_CASES_DEATHS_RECOVERED
         
     | 
| 
       134 
150 
     | 
    
         
             
                    rows = []
         
     | 
| 
       135 
     | 
    
         
            -
                    stats = country['timeline'].values.map(&:values).transpose.each do |data|
         
     | 
| 
       136 
     | 
    
         
            -
                      data.map! { |number| comma_delimit(number) }
         
     | 
| 
       137 
     | 
    
         
            -
                    end
         
     | 
| 
       138 
151 
     | 
    
         | 
| 
       139 
     | 
    
         
            -
                     
     | 
| 
      
 152 
     | 
    
         
            +
                    stats = if last
         
     | 
| 
      
 153 
     | 
    
         
            +
                              country['timeline'].values.map(&:values).transpose.each do |data|
         
     | 
| 
      
 154 
     | 
    
         
            +
                                data.map! { |number| comma_delimit(number) }
         
     | 
| 
      
 155 
     | 
    
         
            +
                              end.last(last.to_i)
         
     | 
| 
      
 156 
     | 
    
         
            +
                            else
         
     | 
| 
      
 157 
     | 
    
         
            +
                              country['timeline'].values.map(&:values).transpose.each do |data|
         
     | 
| 
      
 158 
     | 
    
         
            +
                                data.map! { |number| comma_delimit(number) }
         
     | 
| 
      
 159 
     | 
    
         
            +
                              end
         
     | 
| 
      
 160 
     | 
    
         
            +
                            end
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
                    dates = if last
         
     | 
| 
      
 163 
     | 
    
         
            +
                              country['timeline']['cases'].keys.last(last.to_i)
         
     | 
| 
      
 164 
     | 
    
         
            +
                            else
         
     | 
| 
      
 165 
     | 
    
         
            +
                              country['timeline']['cases'].keys
         
     | 
| 
      
 166 
     | 
    
         
            +
                            end
         
     | 
| 
       140 
167 
     | 
    
         | 
| 
       141 
168 
     | 
    
         
             
                    stats.each_with_index do |val, index|
         
     | 
| 
       142 
169 
     | 
    
         
             
                      val.unshift(Date.parse(Date.strptime(dates[index], '%m/%d/%y').to_s).strftime('%d %b, %y'))
         
     | 
| 
         @@ -144,10 +171,12 @@ module Kovid 
     | 
|
| 
       144 
171 
     | 
    
         
             
                      rows << row
         
     | 
| 
       145 
172 
     | 
    
         
             
                    end
         
     | 
| 
       146 
173 
     | 
    
         | 
| 
       147 
     | 
    
         
            -
                     
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
      
 174 
     | 
    
         
            +
                    if stats.size > 10
         
     | 
| 
      
 175 
     | 
    
         
            +
                      rows << FOOTER_LINE
         
     | 
| 
      
 176 
     | 
    
         
            +
                      rows << DATE_CASES_DEATHS_RECOVERED
         
     | 
| 
      
 177 
     | 
    
         
            +
                    end
         
     | 
| 
       149 
178 
     | 
    
         | 
| 
       150 
     | 
    
         
            -
                    Terminal::Table.new(title: country['standardizedCountryName']. 
     | 
| 
      
 179 
     | 
    
         
            +
                    Terminal::Table.new(title: country['standardizedCountryName'].upcase, headings: headings, rows: rows)
         
     | 
| 
       151 
180 
     | 
    
         
             
                  end
         
     | 
| 
       152 
181 
     | 
    
         | 
| 
       153 
182 
     | 
    
         
             
                  private
         
     | 
| 
         @@ -155,6 +184,14 @@ module Kovid 
     | 
|
| 
       155 
184 
     | 
    
         
             
                  def comma_delimit(number)
         
     | 
| 
       156 
185 
     | 
    
         
             
                    number.to_s.chars.to_a.reverse.each_slice(3).map(&:join).join(',').reverse
         
     | 
| 
       157 
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
         
     | 
| 
       158 
195 
     | 
    
         
             
                end
         
     | 
| 
       159 
196 
     | 
    
         
             
              end
         
     | 
| 
       160 
197 
     | 
    
         
             
            end
         
     | 
    
        data/lib/kovid/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,71 +1,71 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: kovid
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.0
         
     | 
| 
       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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-03-25 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       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: ' 
     | 
| 
      
 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: ' 
     | 
| 
      
 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: ' 
     | 
| 
      
 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: ' 
     | 
| 
      
 54 
     | 
    
         
            +
                    version: '1.3'
         
     | 
| 
       55 
55 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       56 
     | 
    
         
            -
              name:  
     | 
| 
      
 56 
     | 
    
         
            +
              name: rainbow
         
     | 
| 
       57 
57 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       58 
58 
     | 
    
         
             
                requirements:
         
     | 
| 
       59 
     | 
    
         
            -
                - - " 
     | 
| 
      
 59 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       60 
60 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       61 
     | 
    
         
            -
                    version: '0'
         
     | 
| 
      
 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'
         
     | 
| 
      
 68 
     | 
    
         
            +
                    version: '3.0'
         
     | 
| 
       69 
69 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       70 
70 
     | 
    
         
             
              name: pry
         
     | 
| 
       71 
71 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     |