Sha256: 69428b1986960697012359a7d6b74bf95876026bef6eca580cf6c1ba9e7686fc

Contents?: true

Size: 1003 Bytes

Versions: 7

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

require 'terminal-table'

module Kovid
  module_function

  def info_table(message)
    rows = [[message.to_s]]
    puts Terminal::Table.new title: '❗️', rows: rows
  end

  # Parse date as "02 Apr, 20"
  def dateman(date)
    date_to_parse = Date.strptime(date, '%m/%d/%y').to_s
    Date.parse(date_to_parse).strftime('%d %b, %y')
  end

  def comma_delimit(number)
    number.to_s.chars.to_a.reverse.each_slice(3).map(&:join).join(',').reverse
  end

  # Insert + sign to format positive numbers
  def add_plus_sign(num)
    num.to_i.positive? ? "+#{comma_delimit(num)}" : comma_delimit(num).to_s
  end

  def format_country_history_numbers(load)
    load['timeline'].values.map(&:values).transpose.each do |data|
      data.map! { |number| Kovid.comma_delimit(number) }
    end
  end

  def lookup_us_state(state)
    us = Carmen::Country.coded('USA')
    lookup = us.subregions.coded(state) || us.subregions.named(state)
    lookup ? lookup.name : state
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kovid-0.6.13 lib/kovid/helpers.rb
kovid-0.6.12 lib/kovid/helpers.rb
kovid-0.6.11 lib/kovid/helpers.rb
kovid-0.6.10 lib/kovid/helpers.rb
kovid-0.6.9 lib/kovid/helpers.rb
kovid-0.6.8 lib/kovid/helpers.rb
kovid-0.6.7 lib/kovid/helpers.rb