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.


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

#leftObject

Returns the value of attribute left.


94
95
96
# File 'lib/avmtrf1/forponto/user/balance.rb', line 94

def left
  @left
end

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

#requestsObject (readonly)

Returns the value of attribute requests.


94
95
96
# File 'lib/avmtrf1/forponto/user/balance.rb', line 94

def requests
  @requests
end

#unconsumedObject

Returns the value of attribute unconsumed.


94
95
96
# File 'lib/avmtrf1/forponto/user/balance.rb', line 94

def unconsumed
  @unconsumed
end

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


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