Class: Covid19::Decorators::Chart

Inherits:
Object
  • Object
show all
Defined in:
lib/covid19/decorators/chart.rb

Constant Summary collapse

TYPES =
{ all_continent_general_data: 'all_continent_general_data',
continent_general_data: 'continent_general_data',
continent_diary_data: 'continent_diary_data',
country_general_data: 'country_general_data',
country_diary_data: 'country_diary_data' }
DEFAULT_FILL =
'Ø'
SIZE =
15
FILLS =
%w(* x @ + % #)
COLORS =
%i(bright_yellow
bright_green
bright_magenta
bright_cyan
bright_red
bright_white)
GENERAL_TOTALS =
%w(deaths
recovered
active)
DIARY_TOTALS =
%w(todayCases
todayDeaths
todayRecovered)

Class Method Summary collapse

Class Method Details

.create_pie(data:, type:, colored: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/covid19/decorators/chart.rb', line 27

def self.create_pie(data:, type:, colored: nil)
  pie_data = case type
             when TYPES[:all_continent_general_data]
               mount_all_continent_general_data(data)
             when TYPES[:continent_general_data]
               mount_general_data(data)
             when TYPES[:country_general_data]
               mount_general_data(data)
             when TYPES[:continent_diary_data]
               mount_diary_data(data)
             when TYPES[:country_diary_data]
               mount_diary_data(data)
             else
               raise ArgumentError.new('Error in chart plot!')
             end

  formatted_chart = colored ? add_color(pie_data) : add_fill(pie_data)
 
  TTY::Pie.new(data: formatted_chart, radius: SIZE)
end