kovid 0.6.5 → 0.6.6
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/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +59 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +1 -0
- data/kovid.gemspec +9 -4
- data/lib/kovid/aggregators.rb +1 -0
- data/lib/kovid/cache.rb +3 -0
- data/lib/kovid/cli.rb +16 -5
- data/lib/kovid/constants.rb +21 -1
- data/lib/kovid/helpers.rb +16 -0
- data/lib/kovid/historians.rb +12 -6
- data/lib/kovid/painter.rb +1 -0
- data/lib/kovid/request.rb +60 -23
- data/lib/kovid/tablelize.rb +126 -159
- data/lib/kovid/uri_builder.rb +1 -0
- data/lib/kovid/version.rb +1 -1
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6abc6282e6ec84a393eee2b5383d70f88643d7633f8bd7537c207dae341ead1b
         | 
| 4 | 
            +
              data.tar.gz: a93e83c437e3b1f740fe7471cca72ad2e83c837d0a637c5fe8c71636bdd545dd
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: dbc95ba0e85745d9369e15b0e81b6f5d36a7199b1227aaaec56eb57b8aac067750e4e2c71f937a97b333fdf57693547d6f98a09e70d214a5300b5b09cd5eeb25
         | 
| 7 | 
            +
              data.tar.gz: a2a458068aefa1f001ad85426ef5eba0317ba23a0320fab970eed818a9009186cc966f757c0a4f1b693a85cf668098ffa477acc3587849ed5864dcfc53a3b5fe
         | 
    
        data/.rubocop.yml
    ADDED
    
    
    
        data/.rubocop_todo.yml
    ADDED
    
    | @@ -0,0 +1,59 @@ | |
| 1 | 
            +
            # This configuration was generated by
         | 
| 2 | 
            +
            # `rubocop --auto-gen-config`
         | 
| 3 | 
            +
            # on 2020-04-07 20:38:28 -0300 using RuboCop version 0.67.2.
         | 
| 4 | 
            +
            # The point is for the user to remove these configuration records
         | 
| 5 | 
            +
            # one by one as the offenses are removed from the code base.
         | 
| 6 | 
            +
            # Note that changes in the inspected code, or installation of new
         | 
| 7 | 
            +
            # versions of RuboCop, may require this file to be generated again.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            # Offense count: 2
         | 
| 10 | 
            +
            Metrics/AbcSize:
         | 
| 11 | 
            +
              Max: 54
         | 
| 12 | 
            +
              Exclude:
         | 
| 13 | 
            +
                - 'lib/kovid/historians.rb'
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            # Offense count: 2
         | 
| 16 | 
            +
            Metrics/BlockLength:
         | 
| 17 | 
            +
              Exclude:
         | 
| 18 | 
            +
                - 'kovid.gemspec'
         | 
| 19 | 
            +
                - 'spec/kovid_spec.rb'
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            # Offense count: 3
         | 
| 22 | 
            +
            # Configuration parameters: CountComments.
         | 
| 23 | 
            +
            Metrics/ClassLength:
         | 
| 24 | 
            +
              Max: 220
         | 
| 25 | 
            +
              Exclude:
         | 
| 26 | 
            +
                - 'lib/kovid/cli.rb'
         | 
| 27 | 
            +
                - 'lib/kovid/request.rb'
         | 
| 28 | 
            +
                - 'lib/kovid/tablelize.rb'
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            # Offense count: 2
         | 
| 31 | 
            +
            # Configuration parameters: CountComments, ExcludedMethods.
         | 
| 32 | 
            +
            Metrics/MethodLength:
         | 
| 33 | 
            +
              Max: 44
         | 
| 34 | 
            +
              Exclude:
         | 
| 35 | 
            +
                - 'lib/kovid/historians.rb'
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            # Offense count: 1
         | 
| 38 | 
            +
            Metrics/PerceivedComplexity:
         | 
| 39 | 
            +
              Max: 8
         | 
| 40 | 
            +
              Exclude:
         | 
| 41 | 
            +
                - 'lib/kovid/historians.rb'
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            # Offense count: 1
         | 
| 44 | 
            +
            Style/CaseEquality:
         | 
| 45 | 
            +
              Exclude:
         | 
| 46 | 
            +
                - 'lib/kovid/request.rb'
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            Style/Documentation:
         | 
| 49 | 
            +
              Exclude:
         | 
| 50 | 
            +
                - 'spec/**/*'
         | 
| 51 | 
            +
                - 'test/**/*'
         | 
| 52 | 
            +
                - 'lib/kovid.rb'
         | 
| 53 | 
            +
                - 'lib/kovid/helpers.rb'
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            # Offense count: 5
         | 
| 56 | 
            +
            Style/MultilineBlockChain:
         | 
| 57 | 
            +
              Exclude:
         | 
| 58 | 
            +
                - 'lib/kovid/historians.rb'
         | 
| 59 | 
            +
                - 'lib/kovid/request.rb'
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    
    
        data/kovid.gemspec
    CHANGED
    
    | @@ -8,8 +8,10 @@ Gem::Specification.new do |spec| | |
| 8 8 | 
             
              spec.authors       = ['Emmanuel Hayford']
         | 
| 9 9 | 
             
              spec.email         = ['siawmensah@gmail.com']
         | 
| 10 10 |  | 
| 11 | 
            -
               | 
| 12 | 
            -
             | 
| 11 | 
            +
              summary = 'A CLI to fetch and compare the 2019 ' \
         | 
| 12 | 
            +
                        'coronavirus pandemic statistics.'
         | 
| 13 | 
            +
              spec.summary       = summary
         | 
| 14 | 
            +
              spec.description   = summary
         | 
| 13 15 | 
             
              spec.homepage      = 'https://github.com/siaw23/kovid'
         | 
| 14 16 | 
             
              spec.license       = 'MIT'
         | 
| 15 17 | 
             
              spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
         | 
| @@ -29,9 +31,12 @@ Gem::Specification.new do |spec| | |
| 29 31 | 
             
              spec.add_development_dependency 'simplecov', '~>  0.18'
         | 
| 30 32 |  | 
| 31 33 | 
             
              # Specify which files should be added to the gem when it is released.
         | 
| 32 | 
            -
              # The `git ls-files -z` loads the files in the RubyGem | 
| 34 | 
            +
              # The `git ls-files -z` loads the files in the RubyGem
         | 
| 35 | 
            +
              #   that have been added into git.
         | 
| 33 36 | 
             
              spec.files = Dir.chdir(File.expand_path(__dir__)) do
         | 
| 34 | 
            -
                `git ls-files -z`.split("\x0").reject  | 
| 37 | 
            +
                `git ls-files -z`.split("\x0").reject do |f|
         | 
| 38 | 
            +
                  f.match(%r{^(test|spec|features)/})
         | 
| 39 | 
            +
                end
         | 
| 35 40 | 
             
              end
         | 
| 36 41 | 
             
              spec.bindir        = 'exe'
         | 
| 37 42 | 
             
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
    
        data/lib/kovid/aggregators.rb
    CHANGED
    
    
    
        data/lib/kovid/cache.rb
    CHANGED
    
    
    
        data/lib/kovid/cli.rb
    CHANGED
    
    | @@ -4,25 +4,33 @@ require 'thor' | |
| 4 4 | 
             
            require 'kovid'
         | 
| 5 5 |  | 
| 6 6 | 
             
            module Kovid
         | 
| 7 | 
            +
              # Describes the commands that can be run by the user
         | 
| 8 | 
            +
              # Descriptions are returned to STDOUT
         | 
| 7 9 | 
             
              class CLI < Thor
         | 
| 8 10 | 
             
                def self.exit_on_failure?
         | 
| 9 11 | 
             
                  true
         | 
| 10 12 | 
             
                end
         | 
| 11 13 |  | 
| 12 | 
            -
                desc 'province PROVINCE or province "PROVINCE NAME"', | 
| 14 | 
            +
                desc 'province PROVINCE or province "PROVINCE NAME"',
         | 
| 15 | 
            +
                     'Returns reported data on provided province. ' \
         | 
| 16 | 
            +
                     'eg "kovid check "new brunswick".'
         | 
| 13 17 | 
             
                method_option :full, aliases: '-p'
         | 
| 14 18 | 
             
                def province(name)
         | 
| 15 19 | 
             
                  puts Kovid.province(name)
         | 
| 16 20 | 
             
                  data_source
         | 
| 17 21 | 
             
                end
         | 
| 18 22 |  | 
| 19 | 
            -
                desc 'provinces PROVINCE PROVINCE', | 
| 23 | 
            +
                desc 'provinces PROVINCE PROVINCE',
         | 
| 24 | 
            +
                     'Returns full comparison table for the given provinces. ' \
         | 
| 25 | 
            +
                     'Accepts multiple provinces.'
         | 
| 20 26 | 
             
                def provinces(*names)
         | 
| 21 27 | 
             
                  puts Kovid.provinces(names)
         | 
| 22 28 | 
             
                  data_source
         | 
| 23 29 | 
             
                end
         | 
| 24 30 |  | 
| 25 | 
            -
                desc 'check COUNTRY or check "COUNTRY NAME"', | 
| 31 | 
            +
                desc 'check COUNTRY or check "COUNTRY NAME"',
         | 
| 32 | 
            +
                     'Returns reported data on provided country. ' \
         | 
| 33 | 
            +
                     'eg: "kovid check "hong kong".'
         | 
| 26 34 | 
             
                method_option :full, aliases: '-f'
         | 
| 27 35 | 
             
                def check(*name)
         | 
| 28 36 | 
             
                  if name.size == 1
         | 
| @@ -48,7 +56,9 @@ module Kovid | |
| 48 56 | 
             
                  data_source
         | 
| 49 57 | 
             
                end
         | 
| 50 58 |  | 
| 51 | 
            -
                desc 'states STATE STATE or states --all', | 
| 59 | 
            +
                desc 'states STATE STATE or states --all',
         | 
| 60 | 
            +
                     'Returns full comparison table for the given states. ' \
         | 
| 61 | 
            +
                     'Accepts multiple states.'
         | 
| 52 62 | 
             
                method_option :all, aliases: '-a'
         | 
| 53 63 | 
             
                def states(*states)
         | 
| 54 64 | 
             
                  if options[:all]
         | 
| @@ -67,7 +77,8 @@ module Kovid | |
| 67 77 | 
             
                  data_source
         | 
| 68 78 | 
             
                end
         | 
| 69 79 |  | 
| 70 | 
            -
                desc 'history COUNTRY or history COUNTRY N', | 
| 80 | 
            +
                desc 'history COUNTRY or history COUNTRY N',
         | 
| 81 | 
            +
                     'Return history of incidents of COUNTRY (in the last N days)'
         | 
| 71 82 | 
             
                def history(*params)
         | 
| 72 83 | 
             
                  if params.size == 2
         | 
| 73 84 | 
             
                    puts Kovid.history(params.first, params.last)
         | 
    
        data/lib/kovid/constants.rb
    CHANGED
    
    | @@ -63,6 +63,20 @@ module Kovid | |
| 63 63 | 
             
                  'Cases/Million'.paint_white
         | 
| 64 64 | 
             
                ].freeze
         | 
| 65 65 |  | 
| 66 | 
            +
                FULL_PROVINCE_TABLE_HEADINGS = [
         | 
| 67 | 
            +
                  'Confirmed'.paint_white,
         | 
| 68 | 
            +
                  'Deaths'.paint_red,
         | 
| 69 | 
            +
                  'Recovered'.paint_green
         | 
| 70 | 
            +
                ].freeze
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                FULL_STATE_TABLE_HEADINGS = [
         | 
| 73 | 
            +
                  'Cases'.paint_white,
         | 
| 74 | 
            +
                  'Cases Today'.paint_white,
         | 
| 75 | 
            +
                  'Deaths'.paint_red,
         | 
| 76 | 
            +
                  'Deaths Today'.paint_red,
         | 
| 77 | 
            +
                  'Active'.paint_yellow
         | 
| 78 | 
            +
                ].freeze
         | 
| 79 | 
            +
             | 
| 66 80 | 
             
                COMPARE_STATES_HEADINGS = [
         | 
| 67 81 | 
             
                  'State'.paint_white,
         | 
| 68 82 | 
             
                  'Cases'.paint_white,
         | 
| @@ -79,7 +93,13 @@ module Kovid | |
| 79 93 | 
             
                  'Recovered'.paint_green
         | 
| 80 94 | 
             
                ].freeze
         | 
| 81 95 |  | 
| 82 | 
            -
                FOOTER_LINE = [ | 
| 96 | 
            +
                FOOTER_LINE = [
         | 
| 97 | 
            +
                  '------------',
         | 
| 98 | 
            +
                  '------------',
         | 
| 99 | 
            +
                  '------------',
         | 
| 100 | 
            +
                  '------------'
         | 
| 101 | 
            +
                ].freeze
         | 
| 102 | 
            +
             | 
| 83 103 | 
             
                COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
         | 
| 84 104 |  | 
| 85 105 | 
             
                RIGHT_ALIGN_COLUMNS = {
         | 
    
        data/lib/kovid/helpers.rb
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 3 | 
             
            require 'terminal-table'
         | 
| 4 | 
            +
             | 
| 4 5 | 
             
            module Kovid
         | 
| 5 6 | 
             
              module_function
         | 
| 6 7 |  | 
| @@ -14,4 +15,19 @@ module Kovid | |
| 14 15 | 
             
                date_to_parse = Date.strptime(date, '%m/%d/%y').to_s
         | 
| 15 16 | 
             
                Date.parse(date_to_parse).strftime('%d %b, %y')
         | 
| 16 17 | 
             
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              def comma_delimit(number)
         | 
| 20 | 
            +
                number.to_s.chars.to_a.reverse.each_slice(3).map(&:join).join(',').reverse
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              # Insert + sign to format positive numbers
         | 
| 24 | 
            +
              def add_plus_sign(num)
         | 
| 25 | 
            +
                num.to_i.positive? ? "+#{comma_delimit(num)}" : comma_delimit(num).to_s
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              def format_country_history_numbers(load)
         | 
| 29 | 
            +
                load['timeline'].values.map(&:values).transpose.each do |data|
         | 
| 30 | 
            +
                  data.map! { |number| Kovid.comma_delimit(number) }
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 17 33 | 
             
            end
         | 
    
        data/lib/kovid/historians.rb
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 3 | 
             
            module Kovid
         | 
| 4 | 
            +
              # Constructs history data for specified country
         | 
| 4 5 | 
             
              module Historians
         | 
| 5 6 | 
             
                include Constants
         | 
| 6 7 |  | 
| @@ -10,9 +11,9 @@ module Kovid | |
| 10 11 | 
             
                  rows = []
         | 
| 11 12 |  | 
| 12 13 | 
             
                  stats = if last
         | 
| 13 | 
            -
                             | 
| 14 | 
            +
                            Kovid.format_country_history_numbers(country).last(last.to_i)
         | 
| 14 15 | 
             
                          else
         | 
| 15 | 
            -
                             | 
| 16 | 
            +
                            Kovid.format_country_history_numbers(country)
         | 
| 16 17 | 
             
                          end
         | 
| 17 18 |  | 
| 18 19 | 
             
                  dates = if last
         | 
| @@ -53,8 +54,9 @@ module Kovid | |
| 53 54 | 
             
                  end
         | 
| 54 55 |  | 
| 55 56 | 
             
                  # From dates where number of !cases.zero?
         | 
| 56 | 
            -
                   | 
| 57 | 
            -
                   | 
| 57 | 
            +
                  country_cases = country['timeline']['cases']
         | 
| 58 | 
            +
                  positive_cases_figures = country_cases.values.reject(&:zero?)
         | 
| 59 | 
            +
                  dates = country_cases.reject { |_k, v| v.zero? }.keys
         | 
| 58 60 | 
             
                  data = []
         | 
| 59 61 |  | 
| 60 62 | 
             
                  # TODO: Refactor
         | 
| @@ -88,12 +90,16 @@ module Kovid | |
| 88 90 | 
             
                    dates.each_with_index do |val, index|
         | 
| 89 91 | 
             
                      data << [val, positive_cases_figures[index]]
         | 
| 90 92 | 
             
                    end
         | 
| 91 | 
            -
                    y_range = AsciiCharts::Cartesian.new( | 
| 93 | 
            +
                    y_range = AsciiCharts::Cartesian.new(
         | 
| 94 | 
            +
                      data, bar: true, hide_zero: true
         | 
| 95 | 
            +
                    ).y_range
         | 
| 92 96 |  | 
| 93 97 | 
             
                    last_two_y = y_range.last 2
         | 
| 94 98 | 
             
                    y_interval = last_two_y.last - last_two_y.first
         | 
| 95 99 |  | 
| 96 | 
            -
                    scale("Scale on Y: #{y_interval}:#{( | 
| 100 | 
            +
                    scale("Scale on Y: #{y_interval}:#{(
         | 
| 101 | 
            +
                      y_interval / last_two_y.last.to_f * positive_cases_figures.last
         | 
| 102 | 
            +
                    ).round(2) / y_interval}")
         | 
| 97 103 |  | 
| 98 104 | 
             
                    puts 'Experimental feature, please report issues.'
         | 
| 99 105 |  | 
    
        data/lib/kovid/painter.rb
    CHANGED
    
    
    
        data/lib/kovid/request.rb
    CHANGED
    
    | @@ -6,6 +6,7 @@ require_relative 'cache' | |
| 6 6 | 
             
            require_relative 'uri_builder'
         | 
| 7 7 |  | 
| 8 8 | 
             
            module Kovid
         | 
| 9 | 
            +
              # Makes requests to external source to collect cases data
         | 
| 9 10 | 
             
              class Request
         | 
| 10 11 | 
             
                COUNTRIES_PATH = UriBuilder.new('/countries').url
         | 
| 11 12 | 
             
                STATES_URL = UriBuilder.new('/states').url
         | 
| @@ -15,16 +16,18 @@ module Kovid | |
| 15 16 |  | 
| 16 17 | 
             
                EU_ISOS = %w[AT BE BG CY CZ DE DK EE ES FI FR GR HR HU IE IT LT \
         | 
| 17 18 | 
             
                             LU LV MT NL PL PT RO SE SI SK].freeze
         | 
| 18 | 
            -
                EUROPE_ISOS = EU_ISOS + %w[GB IS NO CH MC AD SM VA BA RS ME MK AL\
         | 
| 19 | 
            -
                                           BY UA RU MD]
         | 
| 19 | 
            +
                EUROPE_ISOS = EU_ISOS + %w[GB IS NO CH MC AD SM VA BA RS ME MK AL \
         | 
| 20 | 
            +
                                           BY UA RU MD].freeze
         | 
| 20 21 | 
             
                AFRICA_ISOS = %w[DZ AO BJ BW BF BI CM CV CF TD KM CD CG CI DJ EG \
         | 
| 21 | 
            -
                                 GQ ER SZ ET GA GM GH GN GW KE LS LR LY MG MW ML  | 
| 22 | 
            -
                                 NG RW ST SN SC SL SO ZA SS SD  | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 22 | 
            +
                                 GQ ER SZ ET GA GM GH GN GW KE LS LR LY MG MW ML \
         | 
| 23 | 
            +
                                 MR MU MA MZ NA NE NG RW ST SN SC SL SO ZA SS SD \
         | 
| 24 | 
            +
                                 TZ TG TN UG ZM ZW EH].freeze
         | 
| 25 | 
            +
                SOUTH_AMERICA_ISOS = %w[AR BO BV BR CL CO EC FK GF GY PY PE GS SR \
         | 
| 26 | 
            +
                                        UY VE].freeze
         | 
| 25 27 | 
             
                ASIA_ISOS = %w[AE AF AM AZ BD BH BN BT CC CN CX GE HK ID IL IN \
         | 
| 26 | 
            -
                               IQ IR JO JP KG KH KP KR KW KZ LA LB LK MM MN MO  | 
| 27 | 
            -
                               PS QA SA SG SY TH TJ TL TM TR TW  | 
| 28 | 
            +
                               IQ IR JO JP KG KH KP KR KW KZ LA LB LK MM MN MO \
         | 
| 29 | 
            +
                               MY NP OM PH PK PS QA SA SG SY TH TJ TL TM TR TW \
         | 
| 30 | 
            +
                               UZ VN YE].freeze
         | 
| 28 31 |  | 
| 29 32 | 
             
                class << self
         | 
| 30 33 | 
             
                  def eu_aggregate
         | 
| @@ -147,7 +150,9 @@ module Kovid | |
| 147 150 | 
             
                  end
         | 
| 148 151 |  | 
| 149 152 | 
             
                  def cases
         | 
| 150 | 
            -
                    response = JSON.parse( | 
| 153 | 
            +
                    response = JSON.parse(
         | 
| 154 | 
            +
                      Typhoeus.get(UriBuilder.new('/all').url, cache_ttl: 900).response_body
         | 
| 155 | 
            +
                    )
         | 
| 151 156 |  | 
| 152 157 | 
             
                    Kovid::Tablelize.cases(response)
         | 
| 153 158 | 
             
                  rescue JSON::ParserError
         | 
| @@ -156,7 +161,11 @@ module Kovid | |
| 156 161 |  | 
| 157 162 | 
             
                  def history(country, last)
         | 
| 158 163 | 
             
                    history_path = UriBuilder.new('/v2/historical').url
         | 
| 159 | 
            -
                    response = JSON.parse( | 
| 164 | 
            +
                    response = JSON.parse(
         | 
| 165 | 
            +
                      Typhoeus.get(
         | 
| 166 | 
            +
                        history_path + "/#{country}", cache_ttl: 900
         | 
| 167 | 
            +
                      ).response_body
         | 
| 168 | 
            +
                    )
         | 
| 160 169 |  | 
| 161 170 | 
             
                    Kovid::Tablelize.history(response, last)
         | 
| 162 171 | 
             
                  rescue JSON::ParserError
         | 
| @@ -165,7 +174,11 @@ module Kovid | |
| 165 174 |  | 
| 166 175 | 
             
                  def histogram(country, date)
         | 
| 167 176 | 
             
                    history_path = UriBuilder.new('/v2/historical').url
         | 
| 168 | 
            -
                    response = JSON.parse( | 
| 177 | 
            +
                    response = JSON.parse(
         | 
| 178 | 
            +
                      Typhoeus.get(
         | 
| 179 | 
            +
                        history_path + "/#{country}", cache_ttl: 900
         | 
| 180 | 
            +
                      ).response_body
         | 
| 181 | 
            +
                    )
         | 
| 169 182 |  | 
| 170 183 | 
             
                    Kovid::Tablelize.histogram(response, date)
         | 
| 171 184 | 
             
                  end
         | 
| @@ -183,14 +196,20 @@ module Kovid | |
| 183 196 |  | 
| 184 197 | 
             
                  def fetch_countries(list)
         | 
| 185 198 | 
             
                    list.map do |country|
         | 
| 186 | 
            -
                      JSON.parse( | 
| 199 | 
            +
                      JSON.parse(
         | 
| 200 | 
            +
                        Typhoeus.get(
         | 
| 201 | 
            +
                          COUNTRIES_PATH + "/#{country}", cache_ttl: 900
         | 
| 202 | 
            +
                        ).response_body
         | 
| 203 | 
            +
                      )
         | 
| 187 204 | 
             
                    end.sort_by { |json| -json['cases'] }
         | 
| 188 205 | 
             
                  end
         | 
| 189 206 |  | 
| 190 207 | 
             
                  def fetch_compared_states(submitted_states)
         | 
| 191 208 | 
             
                    state_data = fetch_state_data
         | 
| 192 209 |  | 
| 193 | 
            -
                    state_data.select  | 
| 210 | 
            +
                    state_data.select do |state|
         | 
| 211 | 
            +
                      submitted_states.include?(state['state'].downcase)
         | 
| 212 | 
            +
                    end
         | 
| 194 213 | 
             
                  end
         | 
| 195 214 |  | 
| 196 215 | 
             
                  def fetch_state_data
         | 
| @@ -198,6 +217,10 @@ module Kovid | |
| 198 217 | 
             
                  end
         | 
| 199 218 |  | 
| 200 219 | 
             
                  def fetch_country(country_name)
         | 
| 220 | 
            +
                    # TODO: Match ISOs to full country names
         | 
| 221 | 
            +
                    if country_name == "netherlands"
         | 
| 222 | 
            +
                      country_name = "nl"
         | 
| 223 | 
            +
                    end
         | 
| 201 224 | 
             
                    country_url = COUNTRIES_PATH + "/#{country_name}"
         | 
| 202 225 |  | 
| 203 226 | 
             
                    JSON.parse(Typhoeus.get(country_url, cache_ttl: 900).response_body)
         | 
| @@ -209,7 +232,9 @@ module Kovid | |
| 209 232 |  | 
| 210 233 | 
             
                  def fetch_province(province)
         | 
| 211 234 | 
             
                    response = fetch_jhucsse
         | 
| 212 | 
            -
                    response.select  | 
| 235 | 
            +
                    response.select do |datum|
         | 
| 236 | 
            +
                      datum['province'] == capitalize_words(province)
         | 
| 237 | 
            +
                    end.first
         | 
| 213 238 | 
             
                  end
         | 
| 214 239 |  | 
| 215 240 | 
             
                  def fetch_provinces(provinces)
         | 
| @@ -219,19 +244,35 @@ module Kovid | |
| 219 244 | 
             
                  end
         | 
| 220 245 |  | 
| 221 246 | 
             
                  def fetch_state(state)
         | 
| 222 | 
            -
                    states_array = JSON.parse( | 
| 247 | 
            +
                    states_array = JSON.parse(
         | 
| 248 | 
            +
                      Typhoeus.get(STATES_URL, cache_ttl: 900).response_body
         | 
| 249 | 
            +
                    )
         | 
| 223 250 |  | 
| 224 | 
            -
                    states_array.select  | 
| 251 | 
            +
                    states_array.select do |state_name|
         | 
| 252 | 
            +
                      state_name['state'] == capitalize_words(state)
         | 
| 253 | 
            +
                    end.first
         | 
| 225 254 | 
             
                  end
         | 
| 226 255 |  | 
| 227 256 | 
             
                  def aggregator(isos, meth)
         | 
| 228 | 
            -
                    countries_array = JSON.parse( | 
| 229 | 
            -
             | 
| 257 | 
            +
                    countries_array = JSON.parse(countries_request)
         | 
| 230 258 | 
             
                    country_array = countries_array.select do |hash|
         | 
| 231 259 | 
             
                      isos.include?(hash['countryInfo']['iso2'])
         | 
| 232 260 | 
             
                    end
         | 
| 261 | 
            +
                    data = countries_aggregator(country_array)
         | 
| 262 | 
            +
             | 
| 263 | 
            +
                    meth === data
         | 
| 264 | 
            +
                  rescue JSON::ParserError
         | 
| 265 | 
            +
                    puts SERVER_DOWN
         | 
| 266 | 
            +
                  end
         | 
| 267 | 
            +
             | 
| 268 | 
            +
                  def countries_request
         | 
| 269 | 
            +
                    Typhoeus.get(
         | 
| 270 | 
            +
                      UriBuilder.new('/countries').url, cache_ttl: 900
         | 
| 271 | 
            +
                    ).response_body
         | 
| 272 | 
            +
                  end
         | 
| 233 273 |  | 
| 234 | 
            -
             | 
| 274 | 
            +
                  def countries_aggregator(country_array)
         | 
| 275 | 
            +
                    country_array.inject do |base, other|
         | 
| 235 276 | 
             
                      base.merge(other) do |key, left, right|
         | 
| 236 277 | 
             
                        left  ||= 0
         | 
| 237 278 | 
             
                        right ||= 0
         | 
| @@ -239,10 +280,6 @@ module Kovid | |
| 239 280 | 
             
                        left + right unless %w[country countryInfo].include?(key)
         | 
| 240 281 | 
             
                      end
         | 
| 241 282 | 
             
                    end.compact
         | 
| 242 | 
            -
             | 
| 243 | 
            -
                    meth === data
         | 
| 244 | 
            -
                  rescue JSON::ParserError
         | 
| 245 | 
            -
                    puts SERVER_DOWN
         | 
| 246 283 | 
             
                  end
         | 
| 247 284 | 
             
                end
         | 
| 248 285 | 
             
              end
         | 
    
        data/lib/kovid/tablelize.rb
    CHANGED
    
    | @@ -9,6 +9,7 @@ require_relative 'aggregators' | |
| 9 9 | 
             
            require_relative 'historians'
         | 
| 10 10 |  | 
| 11 11 | 
             
            module Kovid
         | 
| 12 | 
            +
              # Constructs the tables according to specified input
         | 
| 12 13 | 
             
              class Tablelize
         | 
| 13 14 | 
             
                extend Kovid::Constants
         | 
| 14 15 | 
             
                extend Kovid::Aggregators
         | 
| @@ -16,120 +17,50 @@ module Kovid | |
| 16 17 |  | 
| 17 18 | 
             
                class << self
         | 
| 18 19 | 
             
                  def country_table(data)
         | 
| 19 | 
            -
                     | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
                        check_if_positve(data['todayCases']),
         | 
| 23 | 
            -
                        comma_delimit(data['deaths']),
         | 
| 24 | 
            -
                        check_if_positve(data['todayDeaths']),
         | 
| 25 | 
            -
                        comma_delimit(data['recovered'])
         | 
| 26 | 
            -
                      ]
         | 
| 27 | 
            -
                    ]
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                    if (iso = data['countryInfo']['iso2'])
         | 
| 30 | 
            -
                      Terminal::Table.new(title: "#{country_emoji(iso)} #{data['country'].upcase}",
         | 
| 31 | 
            -
                                          headings: CASES_DEATHS_RECOVERED_CTODAY_DTODAY,
         | 
| 32 | 
            -
                                          rows: rows)
         | 
| 33 | 
            -
                    else
         | 
| 34 | 
            -
                      Terminal::Table.new(title: data['country'].upcase,
         | 
| 35 | 
            -
                                          headings: CASES_DEATHS_RECOVERED_CTODAY_DTODAY,
         | 
| 36 | 
            -
                                          rows: rows)
         | 
| 37 | 
            -
                    end
         | 
| 20 | 
            +
                    Terminal::Table.new(title: country_title(data),
         | 
| 21 | 
            +
                                        headings: CASES_DEATHS_RECOVERED_CTODAY_DTODAY,
         | 
| 22 | 
            +
                                        rows: [country_row(data)])
         | 
| 38 23 | 
             
                  end
         | 
| 39 24 |  | 
| 40 25 | 
             
                  def full_country_table(data)
         | 
| 41 | 
            -
                     | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
                      comma_delimit(data['deaths']),
         | 
| 45 | 
            -
                      comma_delimit(data['recovered']),
         | 
| 46 | 
            -
                      check_if_positve(data['todayCases']),
         | 
| 47 | 
            -
                      check_if_positve(data['todayDeaths']),
         | 
| 48 | 
            -
                      comma_delimit(data['critical']),
         | 
| 49 | 
            -
                      comma_delimit(data['casesPerOneMillion'])
         | 
| 50 | 
            -
                    ]
         | 
| 51 | 
            -
             | 
| 52 | 
            -
                    if iso = data['countryInfo']['iso2']
         | 
| 53 | 
            -
                      Terminal::Table.new(title: "#{country_emoji(iso)} #{data['country'].upcase}",
         | 
| 54 | 
            -
                                          headings: FULL_COUNTRY_TABLE_HEADINGS,
         | 
| 55 | 
            -
                                          rows: rows)
         | 
| 56 | 
            -
                    else
         | 
| 57 | 
            -
                      Terminal::Table.new(title: data['country'].upcase,
         | 
| 58 | 
            -
                                          headings: FULL_COUNTRY_TABLE_HEADINGS,
         | 
| 59 | 
            -
                                          rows: rows)
         | 
| 60 | 
            -
                    end
         | 
| 26 | 
            +
                    Terminal::Table.new(title: country_title(data),
         | 
| 27 | 
            +
                                        headings: FULL_COUNTRY_TABLE_HEADINGS,
         | 
| 28 | 
            +
                                        rows: [full_country_row(data)])
         | 
| 61 29 | 
             
                  end
         | 
| 62 30 |  | 
| 63 31 | 
             
                  def full_province_table(province)
         | 
| 64 | 
            -
                     | 
| 65 | 
            -
                      ' | 
| 66 | 
            -
                       | 
| 67 | 
            -
                       | 
| 68 | 
            -
                     | 
| 69 | 
            -
                    rows = []
         | 
| 70 | 
            -
                    rows << [province['stats']['confirmed'], province['stats']['deaths'], province['stats']['recovered']]
         | 
| 71 | 
            -
             | 
| 72 | 
            -
                    Terminal::Table.new(title: province['province'].upcase, headings: headings, rows: rows)
         | 
| 32 | 
            +
                    Terminal::Table.new(
         | 
| 33 | 
            +
                      title: province['province'].upcase,
         | 
| 34 | 
            +
                      headings: FULL_PROVINCE_TABLE_HEADINGS,
         | 
| 35 | 
            +
                      rows: [province_row(province)]
         | 
| 36 | 
            +
                    )
         | 
| 73 37 | 
             
                  end
         | 
| 74 38 |  | 
| 75 39 | 
             
                  def full_state_table(state)
         | 
| 76 | 
            -
                     | 
| 77 | 
            -
                      ' | 
| 78 | 
            -
                       | 
| 79 | 
            -
                       | 
| 80 | 
            -
             | 
| 81 | 
            -
                      'Active'.paint_yellow
         | 
| 82 | 
            -
                    ]
         | 
| 83 | 
            -
             | 
| 84 | 
            -
                    rows = []
         | 
| 85 | 
            -
                    rows << [
         | 
| 86 | 
            -
                      comma_delimit(state['cases']),
         | 
| 87 | 
            -
                      check_if_positve(state['todayCases']),
         | 
| 88 | 
            -
                      comma_delimit(state['deaths']),
         | 
| 89 | 
            -
                      check_if_positve(state['todayDeaths']),
         | 
| 90 | 
            -
                      comma_delimit(state['active'])
         | 
| 91 | 
            -
                    ]
         | 
| 92 | 
            -
             | 
| 93 | 
            -
                    Terminal::Table.new(title: state['state'].upcase, headings: headings, rows: rows)
         | 
| 40 | 
            +
                    Terminal::Table.new(
         | 
| 41 | 
            +
                      title: state['state'].upcase,
         | 
| 42 | 
            +
                      headings: FULL_STATE_TABLE_HEADINGS,
         | 
| 43 | 
            +
                      rows: [country_row(state)]
         | 
| 44 | 
            +
                    )
         | 
| 94 45 | 
             
                  end
         | 
| 95 46 |  | 
| 96 47 | 
             
                  def compare_countries_table(data)
         | 
| 97 48 | 
             
                    rows = []
         | 
| 98 49 |  | 
| 99 50 | 
             
                    data.each do |country|
         | 
| 100 | 
            -
                      base_rows =  | 
| 101 | 
            -
             | 
| 102 | 
            -
                        check_if_positve(country['todayCases']),
         | 
| 103 | 
            -
                        comma_delimit(country['deaths']),
         | 
| 104 | 
            -
                        check_if_positve(country['todayDeaths']),
         | 
| 105 | 
            -
                        comma_delimit(country['recovered'])
         | 
| 106 | 
            -
                      ]
         | 
| 107 | 
            -
             | 
| 108 | 
            -
                      rows << if (iso = country['countryInfo']['iso2'])
         | 
| 109 | 
            -
                                base_rows.unshift("#{country_emoji(iso)} #{country['country'].upcase}")
         | 
| 110 | 
            -
                              else
         | 
| 111 | 
            -
                                base_rows.unshift(country['country'].upcase.to_s)
         | 
| 112 | 
            -
                              end
         | 
| 51 | 
            +
                      base_rows = country_row(country)
         | 
| 52 | 
            +
                      rows << base_rows.unshift(country_title(country))
         | 
| 113 53 | 
             
                    end
         | 
| 114 54 |  | 
| 115 55 | 
             
                    align_columns(:compare_country_table,
         | 
| 116 | 
            -
                                  Terminal::Table.new( | 
| 117 | 
            -
             | 
| 56 | 
            +
                                  Terminal::Table.new(
         | 
| 57 | 
            +
                                    headings: COMPARE_COUNTRIES_TABLE_HEADINGS,
         | 
| 58 | 
            +
                                    rows: rows
         | 
| 59 | 
            +
                                  ))
         | 
| 118 60 | 
             
                  end
         | 
| 119 61 |  | 
| 120 62 | 
             
                  def compare_countries_table_full(data)
         | 
| 121 | 
            -
                    rows = data.map  | 
| 122 | 
            -
                      [
         | 
| 123 | 
            -
                        country.fetch('country'),
         | 
| 124 | 
            -
                        comma_delimit(country.fetch('cases')),
         | 
| 125 | 
            -
                        comma_delimit(country.fetch('deaths')),
         | 
| 126 | 
            -
                        comma_delimit(country.fetch('recovered')),
         | 
| 127 | 
            -
                        check_if_positve(country.fetch('todayCases')),
         | 
| 128 | 
            -
                        check_if_positve(country.fetch('todayDeaths')),
         | 
| 129 | 
            -
                        comma_delimit(country.fetch('critical')),
         | 
| 130 | 
            -
                        comma_delimit(country.fetch('casesPerOneMillion'))
         | 
| 131 | 
            -
                      ]
         | 
| 132 | 
            -
                    end
         | 
| 63 | 
            +
                    rows = data.map { |country| compare_countries_full_row(country) }
         | 
| 133 64 |  | 
| 134 65 | 
             
                    align_columns(:compare_country_table_full,
         | 
| 135 66 | 
             
                                  Terminal::Table.new(headings: COMPARE_COUNTRY_TABLE_FULL,
         | 
| @@ -139,23 +70,9 @@ module Kovid | |
| 139 70 | 
             
                  def compare_us_states(data)
         | 
| 140 71 | 
             
                    rows = data.map.with_index do |state, index|
         | 
| 141 72 | 
             
                      if index.odd?
         | 
| 142 | 
            -
                         | 
| 143 | 
            -
                          state.fetch('state').upcase,
         | 
| 144 | 
            -
                          comma_delimit(state.fetch('cases')),
         | 
| 145 | 
            -
                          check_if_positve(state['todayCases']),
         | 
| 146 | 
            -
                          comma_delimit(state['deaths']),
         | 
| 147 | 
            -
                          check_if_positve(state['todayDeaths']),
         | 
| 148 | 
            -
                          comma_delimit(state.fetch('active'))
         | 
| 149 | 
            -
                        ]
         | 
| 73 | 
            +
                        us_state_row(state)
         | 
| 150 74 | 
             
                      else
         | 
| 151 | 
            -
                         | 
| 152 | 
            -
                          state.fetch('state').upcase.paint_highlight,
         | 
| 153 | 
            -
                          comma_delimit(state.fetch('cases')).paint_highlight,
         | 
| 154 | 
            -
                          check_if_positve(state['todayCases']).paint_highlight,
         | 
| 155 | 
            -
                          comma_delimit(state['deaths']).paint_highlight,
         | 
| 156 | 
            -
                          check_if_positve(state['todayDeaths']).paint_highlight,
         | 
| 157 | 
            -
                          comma_delimit(state.fetch('active')).paint_highlight
         | 
| 158 | 
            -
                        ]
         | 
| 75 | 
            +
                        us_state_row(state).map(&:paint_highlight)
         | 
| 159 76 | 
             
                      end
         | 
| 160 77 | 
             
                    end
         | 
| 161 78 |  | 
| @@ -165,14 +82,7 @@ module Kovid | |
| 165 82 | 
             
                  end
         | 
| 166 83 |  | 
| 167 84 | 
             
                  def compare_provinces(data)
         | 
| 168 | 
            -
                    rows = data.map  | 
| 169 | 
            -
                      [
         | 
| 170 | 
            -
                        province['province'].upcase,
         | 
| 171 | 
            -
                        province['stats']['confirmed'],
         | 
| 172 | 
            -
                        province['stats']['deaths'],
         | 
| 173 | 
            -
                        province['stats']['recovered']
         | 
| 174 | 
            -
                      ]
         | 
| 175 | 
            -
                    end
         | 
| 85 | 
            +
                    rows = data.map { |province| compare_provinces_row(province) }
         | 
| 176 86 |  | 
| 177 87 | 
             
                    align_columns(:compare_provinces,
         | 
| 178 88 | 
             
                                  Terminal::Table.new(headings: COMPARE_PROVINCES_HEADINGS,
         | 
| @@ -180,29 +90,22 @@ module Kovid | |
| 180 90 | 
             
                  end
         | 
| 181 91 |  | 
| 182 92 | 
             
                  def cases(cases)
         | 
| 183 | 
            -
                     | 
| 184 | 
            -
             | 
| 185 | 
            -
                       | 
| 186 | 
            -
             | 
| 187 | 
            -
             | 
| 188 | 
            -
                        comma_delimit(cases['recovered'])
         | 
| 189 | 
            -
                      ]
         | 
| 190 | 
            -
                    ]
         | 
| 191 | 
            -
             | 
| 192 | 
            -
                    Terminal::Table.new(title: '🌍 Total Number of Incidents Worldwide'.upcase, headings: headings, rows: rows)
         | 
| 93 | 
            +
                    Terminal::Table.new(
         | 
| 94 | 
            +
                      title: '🌍 Total Number of Incidents Worldwide'.upcase,
         | 
| 95 | 
            +
                      headings: CASES_DEATHS_RECOVERED,
         | 
| 96 | 
            +
                      rows: [cases_row(cases)]
         | 
| 97 | 
            +
                    )
         | 
| 193 98 | 
             
                  end
         | 
| 194 99 |  | 
| 195 100 | 
             
                  private
         | 
| 196 101 |  | 
| 197 | 
            -
                  def  | 
| 198 | 
            -
                     | 
| 199 | 
            -
             | 
| 200 | 
            -
             | 
| 201 | 
            -
             | 
| 202 | 
            -
             | 
| 203 | 
            -
             | 
| 204 | 
            -
                  def check_if_positve(num)
         | 
| 205 | 
            -
                    num.to_i.positive? ? "+#{comma_delimit(num)}" : comma_delimit(num).to_s
         | 
| 102 | 
            +
                  def country_title(data)
         | 
| 103 | 
            +
                    iso = data['countryInfo']['iso2']
         | 
| 104 | 
            +
                    if iso.nil?
         | 
| 105 | 
            +
                      data['country'].upcase
         | 
| 106 | 
            +
                    else
         | 
| 107 | 
            +
                      "#{country_emoji(iso)} #{data['country'].upcase}"
         | 
| 108 | 
            +
                    end
         | 
| 206 109 | 
             
                  end
         | 
| 207 110 |  | 
| 208 111 | 
             
                  def country_emoji(iso)
         | 
| @@ -210,10 +113,80 @@ module Kovid | |
| 210 113 | 
             
                      8203.chr(Encoding::UTF_8)
         | 
| 211 114 | 
             
                  end
         | 
| 212 115 |  | 
| 213 | 
            -
                  def  | 
| 214 | 
            -
                     | 
| 215 | 
            -
                       | 
| 216 | 
            -
             | 
| 116 | 
            +
                  def cases_row(data)
         | 
| 117 | 
            +
                    [
         | 
| 118 | 
            +
                      Kovid.comma_delimit(data['cases']),
         | 
| 119 | 
            +
                      Kovid.comma_delimit(data['deaths']),
         | 
| 120 | 
            +
                      Kovid.comma_delimit(data['recovered'])
         | 
| 121 | 
            +
                    ]
         | 
| 122 | 
            +
                  end
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                  # Also works for state
         | 
| 125 | 
            +
                  def country_row(data)
         | 
| 126 | 
            +
                    [
         | 
| 127 | 
            +
                      Kovid.comma_delimit(data['cases']),
         | 
| 128 | 
            +
                      Kovid.add_plus_sign(data['todayCases']),
         | 
| 129 | 
            +
                      Kovid.comma_delimit(data['deaths']),
         | 
| 130 | 
            +
                      Kovid.add_plus_sign(data['todayDeaths']),
         | 
| 131 | 
            +
                      Kovid.comma_delimit(data['recovered'])
         | 
| 132 | 
            +
                    ]
         | 
| 133 | 
            +
                  end
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                  def full_country_row(data)
         | 
| 136 | 
            +
                    [
         | 
| 137 | 
            +
                      Kovid.comma_delimit(data['cases']),
         | 
| 138 | 
            +
                      Kovid.comma_delimit(data['deaths']),
         | 
| 139 | 
            +
                      Kovid.comma_delimit(data['recovered']),
         | 
| 140 | 
            +
                      Kovid.add_plus_sign(data['todayCases']),
         | 
| 141 | 
            +
                      Kovid.add_plus_sign(data['todayDeaths']),
         | 
| 142 | 
            +
                      Kovid.comma_delimit(data['critical']),
         | 
| 143 | 
            +
                      Kovid.comma_delimit(data['casesPerOneMillion'])
         | 
| 144 | 
            +
                    ]
         | 
| 145 | 
            +
                  end
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                  def province_row(data)
         | 
| 148 | 
            +
                    [
         | 
| 149 | 
            +
                      data['stats']['confirmed'],
         | 
| 150 | 
            +
                      data['stats']['deaths'],
         | 
| 151 | 
            +
                      data['stats']['recovered']
         | 
| 152 | 
            +
                    ]
         | 
| 153 | 
            +
                  end
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                  def compare_provinces_row(data)
         | 
| 156 | 
            +
                    [
         | 
| 157 | 
            +
                      data['province'].upcase,
         | 
| 158 | 
            +
                      province_row(data)
         | 
| 159 | 
            +
                    ].flatten
         | 
| 160 | 
            +
                  end
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                  def compare_countries_full_row(data)
         | 
| 163 | 
            +
                    [
         | 
| 164 | 
            +
                      data.fetch('country'),
         | 
| 165 | 
            +
                      full_country_row(data)
         | 
| 166 | 
            +
                    ].flatten
         | 
| 167 | 
            +
                  end
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                  def us_state_row(data)
         | 
| 170 | 
            +
                    [
         | 
| 171 | 
            +
                      data.fetch('state').upcase,
         | 
| 172 | 
            +
                      Kovid.comma_delimit(data.fetch('cases')),
         | 
| 173 | 
            +
                      Kovid.add_plus_sign(data['todayCases']),
         | 
| 174 | 
            +
                      Kovid.comma_delimit(data['deaths']),
         | 
| 175 | 
            +
                      Kovid.add_plus_sign(data['todayDeaths']),
         | 
| 176 | 
            +
                      Kovid.comma_delimit(data.fetch('active'))
         | 
| 177 | 
            +
                    ]
         | 
| 178 | 
            +
                  end
         | 
| 179 | 
            +
             | 
| 180 | 
            +
                  def aggregated_row(data)
         | 
| 181 | 
            +
                    [
         | 
| 182 | 
            +
                      Kovid.comma_delimit(data['cases']),
         | 
| 183 | 
            +
                      Kovid.add_plus_sign(data['todayCases']),
         | 
| 184 | 
            +
                      Kovid.comma_delimit(data['deaths']),
         | 
| 185 | 
            +
                      Kovid.add_plus_sign(data['todayDeaths']),
         | 
| 186 | 
            +
                      Kovid.comma_delimit(data['recovered']),
         | 
| 187 | 
            +
                      Kovid.comma_delimit(data['active']),
         | 
| 188 | 
            +
                      Kovid.comma_delimit(data['critical'])
         | 
| 189 | 
            +
                    ]
         | 
| 217 190 | 
             
                  end
         | 
| 218 191 |  | 
| 219 192 | 
             
                  def scale(msg)
         | 
| @@ -222,32 +195,26 @@ module Kovid | |
| 222 195 | 
             
                  end
         | 
| 223 196 |  | 
| 224 197 | 
             
                  def aggregated_table(collated_data, continent, iso, emoji)
         | 
| 225 | 
            -
                    title =  | 
| 226 | 
            -
                              emoji + 8203.chr(Encoding::UTF_8) + \
         | 
| 227 | 
            -
                                " Aggregated Data on #{continent} (#{iso.size} States)".upcase
         | 
| 228 | 
            -
                            else
         | 
| 229 | 
            -
                              emoji + \
         | 
| 230 | 
            -
                                " Aggregated Data on #{continent} (#{iso.size} States)".upcase
         | 
| 231 | 
            -
                            end
         | 
| 232 | 
            -
             | 
| 233 | 
            -
                    rows = []
         | 
| 234 | 
            -
                    rows << [
         | 
| 235 | 
            -
                      comma_delimit(collated_data['cases']),
         | 
| 236 | 
            -
                      check_if_positve(collated_data['todayCases']),
         | 
| 237 | 
            -
                      comma_delimit(collated_data['deaths']),
         | 
| 238 | 
            -
                      check_if_positve(collated_data['todayDeaths']),
         | 
| 239 | 
            -
                      comma_delimit(collated_data['recovered']),
         | 
| 240 | 
            -
                      comma_delimit(collated_data['active']),
         | 
| 241 | 
            -
                      comma_delimit(collated_data['critical'])
         | 
| 242 | 
            -
                    ]
         | 
| 198 | 
            +
                    title = aggregated_table_title(continent, iso, emoji)
         | 
| 243 199 |  | 
| 244 200 | 
             
                    Terminal::Table.new(
         | 
| 245 201 | 
             
                      title: title,
         | 
| 246 202 | 
             
                      headings: CONTINENTAL_AGGREGATE_HEADINGS,
         | 
| 247 | 
            -
                      rows:  | 
| 203 | 
            +
                      rows: [aggregated_row(collated_data)]
         | 
| 248 204 | 
             
                    )
         | 
| 249 205 | 
             
                  end
         | 
| 250 206 |  | 
| 207 | 
            +
                  def aggregated_table_title(continent, iso, emoji)
         | 
| 208 | 
            +
                    aggregated_data_continent = ' Aggregated Data on ' \
         | 
| 209 | 
            +
                      "#{continent} (#{iso.size} States)".upcase
         | 
| 210 | 
            +
             | 
| 211 | 
            +
                    if emoji.codepoints.size > 1
         | 
| 212 | 
            +
                      emoji + 8203.chr(Encoding::UTF_8) + aggregated_data_continent
         | 
| 213 | 
            +
                    else
         | 
| 214 | 
            +
                      emoji + aggregated_data_continent
         | 
| 215 | 
            +
                    end
         | 
| 216 | 
            +
                  end
         | 
| 217 | 
            +
             | 
| 251 218 | 
             
                  def align_columns(table_type, table)
         | 
| 252 219 | 
             
                    return table unless RIGHT_ALIGN_COLUMNS[table_type]
         | 
| 253 220 |  | 
    
        data/lib/kovid/uri_builder.rb
    CHANGED
    
    
    
        data/lib/kovid/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: kovid
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.6. | 
| 4 | 
            +
              version: 0.6.6
         | 
| 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-04- | 
| 11 | 
            +
            date: 2020-04-11 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: ascii_charts
         | 
| @@ -105,6 +105,8 @@ extra_rdoc_files: [] | |
| 105 105 | 
             
            files:
         | 
| 106 106 | 
             
            - ".gitignore"
         | 
| 107 107 | 
             
            - ".rspec"
         | 
| 108 | 
            +
            - ".rubocop.yml"
         | 
| 109 | 
            +
            - ".rubocop_todo.yml"
         | 
| 108 110 | 
             
            - ".travis.yml"
         | 
| 109 111 | 
             
            - CODE_OF_CONDUCT.md
         | 
| 110 112 | 
             
            - Gemfile
         |