Class: Avmtrf1::Tools::Runner::Forponto::Saldo

Inherits:
Object
  • Object
show all
Defined in:
lib/avmtrf1/tools/runner/forponto/saldo.rb

Instance Method Summary collapse

Instance Method Details

#balance_uncachedObject


84
85
86
# File 'lib/avmtrf1/tools/runner/forponto/saldo.rb', line 84

def balance_uncached
  ::Avmtrf1::Forponto::User::Balance.new(runner_context.call(:user))
end

#end_bannerObject


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

def end_banner
  infov 'Crédito final', minutes_to_s(balance.credito_left)
  infov 'Débito final', minutes_to_s(balance.debito_left)
  infov 'Saldo final', minutes_to_s(balance.saldo_left)
end

#left_status(mba) ⇒ Object


66
67
68
69
70
71
72
# File 'lib/avmtrf1/tools/runner/forponto/saldo.rb', line 66

def left_status(mba)
  if mba.left.positive? && mba.owner_month.lost
    '[LOST]'.red
  else
    '[OK]'
  end
end

#minutes_to_s(minutes) ⇒ Object


74
75
76
77
78
79
80
81
82
# File 'lib/avmtrf1/tools/runner/forponto/saldo.rb', line 74

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


16
17
18
19
20
21
# File 'lib/avmtrf1/tools/runner/forponto/saldo.rb', line 16

def run
  balance.months_balances.each do |mb|
    show_balance_month(mb)
  end
  end_banner
end

#show_balance_month(balance_month) ⇒ Object


29
30
31
32
33
34
35
# File 'lib/avmtrf1/tools/runner/forponto/saldo.rb', line 29

def show_balance_month(balance_month)
  infov 'Month', balance_month.month
  show_month_attr_balance(balance_month.credito, 'Crédito')
  show_month_attr_balance(balance_month.debito, 'Débito')
  infov '  * After trigger', minutes_to_s(balance_month.after_trigger)
  infov '  * After trigger acum.', minutes_to_s(balance_month.after_trigger_acum)
end

#show_month_attr_balance(mba, label) ⇒ Object


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

def show_month_attr_balance(mba, label)
  infov "  * #{label}", minutes_to_s(mba.initial_value)
  return unless parsed.details?

  show_month_withdrawals(mba)
  show_month_requests(mba)
  show_month_end_resume(mba)
end

#show_month_end_resume(mba) ⇒ Object


60
61
62
63
64
# File 'lib/avmtrf1/tools/runner/forponto/saldo.rb', line 60

def show_month_end_resume(mba)
  infov '     * Left', minutes_to_s(mba.left) + ' ' + left_status(mba)
  infov '     * After trigger', minutes_to_s(mba.after_trigger)
  infov '     * After trigger acum.', minutes_to_s(mba.after_trigger_acum)
end

#show_month_requests(mba) ⇒ Object


53
54
55
56
57
58
# File 'lib/avmtrf1/tools/runner/forponto/saldo.rb', line 53

def show_month_requests(mba)
  infov '     * Requests', mba.requests.count
  mba.requests.each do |r|
    infov "       * #{r.month.month}", minutes_to_s(r.value)
  end
end

#show_month_withdrawals(mba) ⇒ Object


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

def show_month_withdrawals(mba)
  infov '     * Withdrawals', mba.withdrawals.count
  mba.withdrawals.each do |w|
    infov "       * #{w.month.month}", minutes_to_s(w.value)
  end
end