Class: Covid19::Decorators::Table
- Inherits:
-
Object
- Object
- Covid19::Decorators::Table
- Defined in:
- lib/covid19/decorators/table.rb
Constant Summary collapse
- LOCALITY =
{ country: 'country', continent: 'continent' }
- DEFAULT_HEADER =
%w(cases todayCases deaths todayDeaths recovered todayRecovered active critical tests testsPerOneMillion population)
Class Method Summary collapse
Class Method Details
.create(data:, locality: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/covid19/decorators/table.rb', line 19 def self.create(data:, locality: nil) table = Text::Table.new # Specific data if data.is_a?(Hash) table.head = DEFAULT_HEADER table.rows = [align_fields(filter_data(data).values)] end # Data lists if data.is_a?(Array) && !locality.empty? table.head = DEFAULT_HEADER.unshift(locality) data.each { |line| table.rows << align_fields(filter_data(line).values) } end table.to_s end |