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.
95 96 97 98 99 100 101 102 103 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 95 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.
92 93 94 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 92 def after_trigger @after_trigger end |
#after_trigger_acum ⇒ Object (readonly)
Returns the value of attribute after_trigger_acum.
92 93 94 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 92 def after_trigger_acum @after_trigger_acum end |
#initial_value ⇒ Object (readonly)
Returns the value of attribute initial_value.
92 93 94 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 92 def initial_value @initial_value end |
#left ⇒ Object
Returns the value of attribute left.
92 93 94 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 92 def left @left end |
#owner_month ⇒ Object (readonly)
Returns the value of attribute owner_month.
92 93 94 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 92 def owner_month @owner_month end |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
92 93 94 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 92 def requests @requests end |
#unconsumed ⇒ Object
Returns the value of attribute unconsumed.
92 93 94 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 92 def unconsumed @unconsumed end |
#withdrawals ⇒ Object (readonly)
Returns the value of attribute withdrawals.
92 93 94 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 92 def withdrawals @withdrawals end |
Instance Method Details
#consume_from_months(months) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 109 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
105 106 107 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 105 def to_s "[#{owner_month}|#{attr}]" end |
#withdrawal(month, value) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/avmtrf1/forponto/user/balance.rb', line 119 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) # rubocop:disable Style/OpenStructUse end |