Class: Avmtrf1::Forponto::User::Balance::MyBalance::AttrConsumer

Inherits:
Object
  • Object
show all
Defined in:
lib/avmtrf1/forponto/user/balance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_triggerObject (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_acumObject (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_valueObject (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

#leftObject

Returns the value of attribute left.



92
93
94
# File 'lib/avmtrf1/forponto/user/balance.rb', line 92

def left
  @left
end

#owner_monthObject (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

#requestsObject (readonly)

Returns the value of attribute requests.



92
93
94
# File 'lib/avmtrf1/forponto/user/balance.rb', line 92

def requests
  @requests
end

#unconsumedObject

Returns the value of attribute unconsumed.



92
93
94
# File 'lib/avmtrf1/forponto/user/balance.rb', line 92

def unconsumed
  @unconsumed
end

#withdrawalsObject (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_sObject



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