Class: Avmtrf1::Forponto::User::Balance::MyBalance::AttrConsumer
- Inherits:
-
Object
- Object
- Avmtrf1::Forponto::User::Balance::MyBalance::AttrConsumer
- Defined in:
- lib/avmtrf1/forponto/user/balance.rb
Instance Attribute Summary collapse
-
#after_trigger ⇒ Object
readonly
Returns the value of attribute after_trigger.
-
#after_trigger_acum ⇒ Object
readonly
Returns the value of attribute after_trigger_acum.
-
#initial_value ⇒ Object
readonly
Returns the value of attribute initial_value.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#owner_month ⇒ Object
readonly
Returns the value of attribute owner_month.
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
-
#unconsumed ⇒ Object
readonly
Returns the value of attribute unconsumed.
-
#withdrawals ⇒ Object
readonly
Returns the value of attribute withdrawals.
Instance Method Summary collapse
- #consume_from_months(months) ⇒ Object
-
#initialize(owner_month, credito, initial_value) ⇒ AttrConsumer
constructor
A new instance of AttrConsumer.
- #to_s ⇒ Object
- #withdrawal(month, value) ⇒ Object
Constructor Details
#initialize(owner_month, credito, initial_value) ⇒ AttrConsumer
Returns a new instance of AttrConsumer.
97 98 99 100 101 102 103 104 105 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 97 def initialize(owner_month, credito, initial_value) @owner_month = owner_month @credito = credito @left = initial_value @initial_value = initial_value @withdrawals = [] @requests = [] @after_trigger = nil end |
Instance Attribute Details
#after_trigger ⇒ Object (readonly)
Returns the value of attribute after_trigger.
94 95 96 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 94 def after_trigger @after_trigger end |
#after_trigger_acum ⇒ Object (readonly)
Returns the value of attribute after_trigger_acum.
94 95 96 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 94 def after_trigger_acum @after_trigger_acum end |
#initial_value ⇒ Object (readonly)
Returns the value of attribute initial_value.
94 95 96 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 94 def initial_value @initial_value end |
#left ⇒ Object
Returns the value of attribute left.
94 95 96 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 94 def left @left end |
#owner_month ⇒ Object (readonly)
Returns the value of attribute owner_month.
94 95 96 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 94 def owner_month @owner_month end |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
94 95 96 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 94 def requests @requests end |
#unconsumed ⇒ Object
Returns the value of attribute unconsumed.
94 95 96 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 94 def unconsumed @unconsumed end |
#withdrawals ⇒ Object (readonly)
Returns the value of attribute withdrawals.
94 95 96 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 94 def withdrawals @withdrawals end |
Instance Method Details
#consume_from_months(months) ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 111 def consume_from_months(months) (months + [owner_month]).each do |month| break unless left.positive? consume_from_month(month) end @after_trigger = left @after_trigger_acum = months.inject(0) { |a, e| a + e.send(attr).left } + left end |
#to_s ⇒ Object
107 108 109 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 107 def to_s "[#{owner_month}|#{attr}]" end |
#withdrawal(month, value) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 121 def withdrawal(month, value) month.assert_argument(MyBalance, :month) raise "Value is not positive: #{value} (Month: #{month})" unless value.positive? self.left -= value raise "Left less than zero: #{left} (Value: #{value})" if left.negative? @withdrawals << OpenStruct.new(month: month, value: value) end |