class Pueri::Vax

Gets input from child vaccination calendar for children (PNI) and an age in days. With this, process which vaccines are due by that age.

Attributes

calendar[R]
header[R]
notes[R]
range[R]
table[R]

Public Class Methods

new(norm_age) click to toggle source
# File lib/pueri/vax.rb, line 10
def initialize(norm_age)
  init_base
  @range = calc_range(norm_age)
  parse_calendar
end

Public Instance Methods

parse_notes() click to toggle source

Retrieves the notes for the vaccination calendar, prettified.

@return [String] The notes for the vaccines' calendar.

# File lib/pueri/vax.rb, line 19
def parse_notes
  r = ''
  max = @notes.size
  p = Pastel.new

  @notes.each_with_index do |line, k|
    pre = ' ' * (max - (k + 1))
    pre += '*' * (k.to_i + 1)
    r += "\n#{p.cyan(pre)} #{line}"
  end

  r
end

Private Instance Methods

calc_range(norm_age) click to toggle source

rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength Disabled rubocop for this method for breaking this switch apart will make it less readable than keeping it as a whole logic.

# File lib/pueri/vax.rb, line 102
def calc_range(norm_age)
  r = case norm_age
      when 0.01..59.99 then 0
      when 60.0..89.99 then 1
      when 90.0..119.99 then 2
      when 120.0..149.99 then 3
      when 150.0..179.99 then 4
      when 180.0..269.99 then 5
      when 270.0..365.24 then 6
      when 365.25..455.24 then 7
      when 455.25..1460.99 then 8
      when 1461.0..3287.24 then 9
      when 3287.25..50_000.0 then 10
      else out_of_range
      end
  r
end
init_base() click to toggle source
# File lib/pueri/vax.rb, line 35
def init_base
  init_header
  init_calendar
  init_notes
end
init_calendar() click to toggle source
# File lib/pueri/vax.rb, line 47
def init_calendar
  part1 = init_calendar1
  part2 = init_calendar2
  @calendar = part1.concat part2
end
init_calendar1() click to toggle source
# File lib/pueri/vax.rb, line 53
def init_calendar1
  [
    ['DU', '1ª', '', '', '', '', '', '', '', '', '', '', '', ''],
    ['', '', '1ª', '1ª VIP', '1ª', '1ª', '', '', '', '', '', '', '', ''],
    ['', '', '', '', '', '', '1ª', '', '', '', '', '', '', ''],
    ['', '', '2ª', '2ª VIP', '2ª', '2ª', '', '', '', '', '', '', '', ''],
    ['', '', '', '', '', '', '2ª', '', '', '', '', '', '', ''],
    ['', '', '3ª', '3ª VIP', '', '', '', '', '', '', '', '', '', '**']
  ]
end
init_calendar2() click to toggle source
# File lib/pueri/vax.rb, line 64
def init_calendar2
  [
    ['', '', '', '', '', '', '', 'DU', '', '', '', '', '', '**'],
    ['', '', '', '', 'Ref', '', 'Ref', '', '', '1ª', '', '', '', '**'],
    ['', '', 'DTP', '1ª VOP', '', '', '', '', 'DU', '', 'DU', '', '', '**'],
    ['', '', 'DTP', '2ª VOP', '', '', '', '', '', '', '', 'DU', '', '**'],
    ['', '', '', '', '', '', '', '', '', '', '', '', '***', '']
  ]
end
init_header() click to toggle source
# File lib/pueri/vax.rb, line 41
def init_header
  @header = ['BCB', 'HepB', 'Penta', 'Polio', 'Pneumo 10V', 'Rota',
             'MeningoC', 'FA', 'HepA', 'SCR', 'Tetra*', 'Varicela',
             'HPV', 'Influenza']
end
init_notes() click to toggle source
# File lib/pueri/vax.rb, line 74
def init_notes
  @notes = [
    'A vacina tetra viral corresponde à segunda dose de SCR e a uma dose '\
    'de Varicela.',
    'A partir dos 6 meses aos 6 anos incompletos, uma dose por ano, exceto'\
    ' no primeiro ano de vida, quase se oferta duas doses.',
    'Meninas de 9 a 14 anos. Meninos de 11 a 14 anos. Duas doses com '\
    'intervalo de 6 meses.'
  ]
end
out_of_range() click to toggle source
# File lib/pueri/vax.rb, line 94
def out_of_range
  m = 'The given age is out of reality bounds'
  raise ArgumentError, m
end
parse_calendar() click to toggle source
# File lib/pueri/vax.rb, line 85
def parse_calendar
  table_obj = TTY::Table.new(header: @header) do |table_line|
    @calendar[0..@range].each do |line|
      table_line << line
    end
  end
  @table = table_obj.render(:unicode, alignment: :center)
end