Class: Avmtrf1::Forponto::User::Balance
- Inherits:
-
Object
- Object
- Avmtrf1::Forponto::User::Balance
- Includes:
- EacRubyUtils::SimpleCache
- Defined in:
- lib/avmtrf1/forponto/user/balance.rb
Defined Under Namespace
Classes: MyBalance
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #credito_left ⇒ Object
- #debito_left ⇒ Object
- #head_month ⇒ Object
-
#initialize(user) ⇒ Balance
constructor
A new instance of Balance.
- #months_balances_uncached ⇒ Object
- #saldo_left ⇒ Object
- #sorted_months_uncached ⇒ Object
Constructor Details
#initialize(user) ⇒ Balance
Returns a new instance of Balance.
11 12 13 14 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 11 def initialize(user) @user = user build_balances end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
9 10 11 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 9 def user @user end |
Instance Method Details
#credito_left ⇒ Object
40 41 42 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 40 def credito_left months_balances.inject(0) { |a, e| a + e.credito.left } end |
#debito_left ⇒ Object
36 37 38 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 36 def debito_left months_balances.inject(0) { |a, e| a + e.debito.left } end |
#head_month ⇒ Object
30 31 32 33 34 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 30 def head_month today = ::Date.today # rubocop:disable Rails/Date date = ::Date.civil(today.year, today.month, 1) user.month(date.year, date.month) end |
#months_balances_uncached ⇒ Object
16 17 18 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 16 def months_balances_uncached sorted_months.map { |m| MyBalance.new(m) } end |
#saldo_left ⇒ Object
44 45 46 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 44 def saldo_left credito_left - debito_left end |
#sorted_months_uncached ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 20 def sorted_months_uncached r = [] current = head_month while current.present? r << current current = current.parent_month end r.reverse end |