Class: FootballCli::Format::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/football_cli/format/table.rb

Instance Attribute Summary

Attributes inherited from Base

#columns, #response, #rows, #title

Instance Method Summary collapse

Methods inherited from Base

#goal_columns, #initialize, #output, #qualification

Constructor Details

This class inherits a constructor from FootballCli::Format::Base

Instance Method Details

#generateObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/football_cli/format/table.rb', line 7

def generate
  response.each do |data|
    rows.push(columns.collect {|column| pretty_table(data, column) })
  end

  @generate ||= Terminal::Table.new do |t|
    t.title = title
    t.headings = columns.map(&:capitalize)
    t.rows = rows
  end
end

#get_color(data) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/football_cli/format/table.rb', line 29

def get_color(data)
  case data
  when qualification[:cl] then :green
  when qualification[:el] then :yellow
  when qualification[:rl] then :red
  else
    :aqua
  end
end

#pretty_table(data, column) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/football_cli/format/table.rb', line 19

def pretty_table(data, column)
  if qualification
    data[column].to_s.color(get_color(data[:position]))
  elsif goal_columns.include?(column) && data[:result]
    data[:result][column]
  else
    data[column]
  end
end