Class: IGMarkets::CLI::Tables::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/ig_markets/cli/tables/table.rb

Overview

Base class with shared table setup and display methods. Used to print output tables in the command-line client.

Instance Method Summary collapse

Constructor Details

#initialize(models, options = {}) ⇒ Table

Initializer that takes the array of models to display in this table.

Parameters:

  • models (Array)

    The array of models.

  • options (Hash) (defaults to: {})

    The options hash.

Options Hash (options):

  • :title (String)

    The title for this table.



11
12
13
14
# File 'lib/ig_markets/cli/tables/table.rb', line 11

def initialize(models, options = {})
  @models = Array(models).flatten
  @title = options[:title] || default_title
end

Instance Method Details

#linesArray<String>

Returns the individual formatted lines that make up this table.

Returns:

  • (Array<String>)


24
25
26
# File 'lib/ig_markets/cli/tables/table.rb', line 24

def lines
  to_s.split "\n"
end

#to_sObject

Converts this table into a formatted string.



17
18
19
# File 'lib/ig_markets/cli/tables/table.rb', line 17

def to_s
  table.to_s
end