Class: Kovid::Tablelize
Constant Summary
Constants included
from Constants
Constants::ADD_FOOTER_SIZE, Constants::CASES_DEATHS_RECOVERED, Constants::CASES_DEATHS_RECOVERED_CTODAY_DTODAY, Constants::COMPARE_COUNTRIES_TABLE_HEADINGS, Constants::COMPARE_COUNTRY_TABLE_FULL, Constants::COMPARE_PROVINCES_HEADINGS, Constants::COMPARE_STATES_HEADINGS, Constants::CONTINENTAL_AGGREGATE_HEADINGS, Constants::COUNTRY_LETTERS, Constants::DATE_CASES_DEATHS, Constants::DATE_CASES_DEATHS_RECOVERED, Constants::FOOTER_LINE_COLUMN, Constants::FOOTER_LINE_FOUR_COLUMNS, Constants::FOOTER_LINE_THREE_COLUMNS, Constants::FULL_COUNTRY_TABLE_HEADINGS, Constants::FULL_PROVINCE_TABLE_HEADINGS, Constants::FULL_STATE_TABLE_HEADINGS, Constants::RIGHT_ALIGN_COLUMNS, Constants::USA_ABBREVIATIONS
Constants included
from AsciiCharts
AsciiCharts::VERSION
Class Method Summary
collapse
africa_aggregate, asia_aggregate, eu_aggregate, europe_aggregate, south_america_aggregate
Methods included from Historians
histogram, history, history_us_state
Class Method Details
.cases(cases) ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/kovid/tablelize.rb', line 91
def cases(cases)
Terminal::Table.new(
title: '🌍 Total Number of Incidents Worldwide'.upcase,
headings: CASES_DEATHS_RECOVERED,
rows: [cases_row(cases)]
)
end
|
.compare_countries_table(data) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/kovid/tablelize.rb', line 46
def compare_countries_table(data)
rows = []
data.each do |country|
base_rows = country_row(country)
rows << base_rows.unshift(country_title(country))
end
align_columns(:compare_country_table,
Terminal::Table.new(
headings: COMPARE_COUNTRIES_TABLE_HEADINGS,
rows: rows
))
end
|
.compare_countries_table_full(data) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/kovid/tablelize.rb', line 61
def compare_countries_table_full(data)
rows = data.map { |country| compare_countries_full_row(country) }
align_columns(:compare_country_table_full,
Terminal::Table.new(headings: COMPARE_COUNTRY_TABLE_FULL,
rows: rows))
end
|
.compare_provinces(data) ⇒ Object
83
84
85
86
87
88
89
|
# File 'lib/kovid/tablelize.rb', line 83
def compare_provinces(data)
rows = data.map { |province| compare_provinces_row(province) }
align_columns(:compare_provinces,
Terminal::Table.new(headings: COMPARE_PROVINCES_HEADINGS,
rows: rows))
end
|
.compare_us_states(data) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/kovid/tablelize.rb', line 69
def compare_us_states(data)
rows = data.map.with_index do |state, index|
if index.odd?
us_state_row(state)
else
us_state_row(state).map(&:paint_highlight)
end
end
align_columns(:compare_us_states,
Terminal::Table.new(headings: COMPARE_STATES_HEADINGS,
rows: rows))
end
|
.country_table(data) ⇒ Object
18
19
20
21
22
|
# File 'lib/kovid/tablelize.rb', line 18
def country_table(data)
Terminal::Table.new(title: country_title(data),
headings: CASES_DEATHS_RECOVERED_CTODAY_DTODAY,
rows: [country_row(data)])
end
|
.full_country_table(data) ⇒ Object
24
25
26
27
28
|
# File 'lib/kovid/tablelize.rb', line 24
def full_country_table(data)
Terminal::Table.new(title: country_title(data),
headings: FULL_COUNTRY_TABLE_HEADINGS,
rows: [full_country_row(data)])
end
|
.full_province_table(province) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/kovid/tablelize.rb', line 30
def full_province_table(province)
Terminal::Table.new(
title: province['province'].upcase,
headings: FULL_PROVINCE_TABLE_HEADINGS,
rows: [province_row(province)]
)
end
|
.full_state_table(state) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/kovid/tablelize.rb', line 38
def full_state_table(state)
Terminal::Table.new(
title: state['state'].upcase,
headings: FULL_STATE_TABLE_HEADINGS,
rows: [state_row(state)]
)
end
|
.top(data, options) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/kovid/tablelize.rb', line 99
def top(data, options)
headings = top_heading(options)
rows = data.map { |location| top_row(location, options) }
if options[:count] > 10
rows << FOOTER_LINE_COLUMN * headings.count
rows << headings
end
Terminal::Table.new(
title: top_title(options),
headings: headings,
rows: rows
)
end
|