Class: Avmtrf1::Tools::Runner::Forponto::Resumos

Inherits:
EacRubyUtils::Console::DocoptRunner
  • Object
show all
Includes:
EacRubyUtils::Console::Speaker, EacRubyUtils::SimpleCache
Defined in:
lib/avmtrf1/tools/runner/forponto/resumos.rb

Constant Summary collapse

DOC =
<<~DOCOPT
    Mostra os resumos.

    Usage:
      __PROGRAM__ [options]
      __PROGRAM__ -h | --help

  Options:
    -h --help                   Show this screen.
DOCOPT

Instance Method Summary collapse

Instance Method Details

#head_monthObject



32
33
34
35
36
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 32

def head_month
  today = ::Date.today
  date = ::Date.civil(today.year, today.month, 1)
  context(:user).month(date.year, date.month)
end

#minutes_to_s(minutes) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 76

def minutes_to_s(minutes)
  signal = ''
  if minutes.negative?
    signal = '-'
    minutes = -minutes
  end
  time = [minutes / 60, minutes % 60].map { |x| x.to_s.rjust(2, '0') }.join(':')
  "#{signal}#{time} / #{signal}#{minutes} minutes"
end

#runObject



26
27
28
29
30
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 26

def run
  sorted_months.each do |month|
    show_month(month)
  end
end

#show_month(month) ⇒ Object



38
39
40
41
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 38

def show_month(month)
  infov 'Month', month
  show_self_summaries(month)
end

#show_month_acum_summaries(month) ⇒ Object



62
63
64
65
66
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 62

def show_month_acum_summaries(month)
  infov '  * Débito acum.', minutes_to_s(month.debito_acum)
  infov '  * Crédito acum.', minutes_to_s(month.credito_acum)
  infov '  * Saldo acum.', minutes_to_s(month.saldo_acum)
end

#show_month_self_summaries(month) ⇒ Object



56
57
58
59
60
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 56

def show_month_self_summaries(month)
  infov '  * Débito', minutes_to_s(month.debito)
  infov '  * Crédito', minutes_to_s(month.credito)
  infov '  * Saldo', minutes_to_s(month.saldo)
end

#show_month_summaries(month) ⇒ Object



50
51
52
53
54
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 50

def show_month_summaries(month)
  month.os_data.summaries.each do |s|
    infov '    * ' + summary_to_label(s), summary_to_value(s)
  end
end

#show_self_summaries(month) ⇒ Object



43
44
45
46
47
48
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 43

def show_self_summaries(month)
  infov '  * Self summaries', month.os_data.summaries.count
  show_month_summaries(month)
  show_month_self_summaries(month)
  show_month_acum_summaries(month)
end

#sorted_months_uncachedObject



86
87
88
89
90
91
92
93
94
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 86

def sorted_months_uncached
  r = []
  current = head_month
  while current.present?
    r << current
    current = current.parent_month
  end
  r.reverse
end

#summary_to_label(summary) ⇒ Object



68
69
70
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 68

def summary_to_label(summary)
  "#{summary.code} - #{summary.description}"
end

#summary_to_value(summary) ⇒ Object



72
73
74
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 72

def summary_to_value(summary)
  minutes_to_s(summary.minutes)
end