Class: Capwatch::Console

Inherits:
Object
  • Object
show all
Extended by:
ConsoleFormatter
Defined in:
lib/capwatch.rb

Class Method Summary collapse

Methods included from ConsoleFormatter

condition_color, fmt, format_btc, format_eth, format_percent

Class Method Details

.colorize_table(hash) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/capwatch.rb', line 157

def self.colorize_table(hash)
  hash[:table_array].each do |x|
    x[2] = fmt(x[2])
    x[3] = fmt(x[3])
    x[4] = format_btc(x[4])
    x[5] = format_eth(x[5])
    x[6] = format_percent(x[6])
    x[7] = condition_color(format_percent(x[7]))
    x[8] = condition_color(format_percent(x[8]))
    x[9] = condition_color(format_percent(x[9]))
  end
  hash[:footer_row][3] = fmt(hash[:footer_row][3])
  hash[:footer_row][4] = format_btc(hash[:footer_row][4])
  hash[:footer_row][5] = format_eth(hash[:footer_row][5])
  hash[:footer_row][7] = condition_color(format_percent(hash[:footer_row][7]))
  hash[:footer_row][8] = condition_color(format_percent(hash[:footer_row][8]))
  hash[:footer_row][9] = condition_color(format_percent(hash[:footer_row][9]))
  hash
end

.draw_table(hash) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/capwatch.rb', line 177

def self.draw_table(hash)
  hash = colorize_table(hash)
  table = Terminal::Table.new do |t|
    t.title = hash[:title].upcase
    t.style = {
      border_top: false,
      border_bottom: false,
      border_y: '',
      border_i: '',
      padding_left: 1,
      padding_right: 1
    }
    t.headings = [
      'ASSET',
      'QUANTITY',
      'PRICE',
      'VALUE (USD)',
      'VALUE (BTC)',
      'VALUE (ETH)',
      'DIST (%)',
      '%(1H)',
      '%(24H)',
      '%(7D)'
    ]
    hash[:table_array].each do |x|
      t << x
    end
    t.add_separator
    t.add_row hash[:footer_row]
  end

  table
end