Sha256: 3351d19036a12703ec5c77f17985f6b2509ae3e77a87cd418fa291f0da3a68e9

Contents?: true

Size: 826 Bytes

Versions: 1

Compression:

Stored size: 826 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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kovid-0.6.6 lib/kovid/helpers.rb