Module: CovidPT

Extended by:
CovidPT
Included in:
CovidPT
Defined in:
lib/covid_pt.rb,
lib/covid_pt/utils.rb,
lib/covid_pt/report.rb,
lib/covid_pt/printer.rb,
lib/covid_pt/version.rb

Defined Under Namespace

Modules: Printer, Utils Classes: Error, Report

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Instance Method Details

#at(date) ⇒ Object



12
13
14
# File 'lib/covid_pt.rb', line 12

def at(date)
  CovidPT::Report.new(date).generate.merge({type: "report"})
end

#compare(from, to) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/covid_pt.rb', line 16

def compare(from, to)
  report_1 = CovidPT::Report.new(from).generate
  report_2 = CovidPT::Report.new(to).generate

  {
    overall: Utils.diff(report_2[:overall], report_1[:overall]),
    regional: Utils.diff(report_2[:regional], report_1[:regional]),
    dates: {
      from: report_1[:date],
      to: report_2[:date]
    },
    type: "comparison"
  }
end

#range(from, to) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/covid_pt.rb', line 31

def range(from, to)
  from_date = Date.parse(from)
  to_date = Date.parse(to)

  dates = (from_date..to_date).to_a
  reports = (from_date..to_date).map { |d| CovidPT::Report.new(d.to_s).generate }

  i = 0
  acc = {overall: {}, regional: {}, dates: dates, type: "range"}

  while i < reports.length - 1 do
    report_1 = reports[i]
    report_2 = reports[i + 1]

    acc[:overall] = Utils.cumulative_diff(
      report_1[:overall],
      report_2[:overall],
      acc[:overall]
    )

    acc[:regional] = Utils.cumulative_diff(
      report_1[:regional],
      report_2[:regional],
      acc[:regional]
    )

    i += 1
  end

  acc
end