class Exrt::Cli::Renderer

Attributes

data[R]
table[R]
type[R]

Public Class Methods

new(d:, t:) click to toggle source
# File lib/exrt/cli/renderer.rb, line 12
def initialize(d:, t:)
  @data = d
  @type = t
  @table = TTY::Table.new header, rows
end

Public Instance Methods

header() click to toggle source
# File lib/exrt/cli/renderer.rb, line 26
def header
  if is_latest?
    latest_table_header
  elsif is_history?
    history_table_header
  else
    []
  end
end
history_table_header() click to toggle source
# File lib/exrt/cli/renderer.rb, line 50
def history_table_header
  %w[Currency Rate Date]
end
is_history?() click to toggle source
# File lib/exrt/cli/renderer.rb, line 22
def is_history?
  type == Exrt::Cli::HISTORY
end
is_latest?() click to toggle source
# File lib/exrt/cli/renderer.rb, line 18
def is_latest?
  type == Exrt::Cli::LATEST
end
latest_table_header() click to toggle source
# File lib/exrt/cli/renderer.rb, line 46
def latest_table_header
  %w[Currency Rate]
end
render() click to toggle source
# File lib/exrt/cli/renderer.rb, line 54
def render
  table.render(:ascii)
end
rows() click to toggle source
# File lib/exrt/cli/renderer.rb, line 36
def rows
  if is_latest?
    Exrt::Cli::Format.latest(data)
  elsif is_history?
    Exrt::Cli::Format.history(data)
  else
    []
  end
end