class Capwatch::List

Public Class Methods

format(response, limit: 50) click to toggle source
# File lib/capwatch/list.rb, line 6
def self.format(response, limit: 50)
  response.first(limit).map do |coin|
    [
      coin["name"],
      Console::Formatter.format_usd(coin["price_usd"]),
      Console::Formatter.condition_color(Console::Formatter.format_percent(coin["percent_change_24h"])),
      Console::Formatter.condition_color(Console::Formatter.format_percent(coin["percent_change_7d"]))
    ]
  end
end
watch() click to toggle source
# File lib/capwatch/list.rb, line 17
def self.watch
  response = Providers::CoinMarketCap.new.fetched_json
  body = format(response)
  table  = Terminal::Table.new do |t|
    t.style = {
      # border_top: false,
      border_bottom: false,
      border_y: "",
      border_i: "",
      padding_left: 1,
      padding_right: 1
    }
    t.headings = [
      "SYMBOL",
      "PRICE",
      "24H %",
      "7D %"
    ]
    body.each { |x| t << x }
  end

  table
end