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



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

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



72
73
74
75
76
77
78
79
80
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 72

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



22
23
24
25
26
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 22

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

#show_month(month) ⇒ Object



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

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

#show_month_acum_summaries(month) ⇒ Object



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

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



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

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



46
47
48
49
50
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 46

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



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

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



82
83
84
85
86
87
88
89
90
# File 'lib/avmtrf1/tools/runner/forponto/resumos.rb', line 82

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



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

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

#summary_to_value(summary) ⇒ Object



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

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