Class: Legion::Extensions::Agentic::Executive::CognitiveDebt::Helpers::DebtItem
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::CognitiveDebt::Helpers::DebtItem
- Defined in:
- lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb
Instance Attribute Summary collapse
-
#accrued_interest ⇒ Object
readonly
Returns the value of attribute accrued_interest.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#debt_type ⇒ Object
readonly
Returns the value of attribute debt_type.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#principal ⇒ Object
readonly
Returns the value of attribute principal.
-
#repaid_at ⇒ Object
readonly
Returns the value of attribute repaid_at.
Instance Method Summary collapse
- #accrue! ⇒ Object
- #age_seconds ⇒ Object
-
#initialize(label:, debt_type:, principal:, domain:) ⇒ DebtItem
constructor
A new instance of DebtItem.
- #repaid? ⇒ Boolean
- #repay!(amount: Constants::REPAYMENT_RATE) ⇒ Object
- #severity_label ⇒ Object
- #to_h ⇒ Object
- #total_cost ⇒ Object
Constructor Details
#initialize(label:, debt_type:, principal:, domain:) ⇒ DebtItem
Returns a new instance of DebtItem.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 15 def initialize(label:, debt_type:, principal:, domain:) @id = SecureRandom.uuid @label = label @debt_type = debt_type.to_sym @principal = principal.clamp(0.0, Float::INFINITY) @accrued_interest = 0.0 @domain = domain @created_at = Time.now.utc @repaid_at = nil end |
Instance Attribute Details
#accrued_interest ⇒ Object (readonly)
Returns the value of attribute accrued_interest.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 12 def accrued_interest @accrued_interest end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 12 def created_at @created_at end |
#debt_type ⇒ Object (readonly)
Returns the value of attribute debt_type.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 12 def debt_type @debt_type end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 12 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 12 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 12 def label @label end |
#principal ⇒ Object (readonly)
Returns the value of attribute principal.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 12 def principal @principal end |
#repaid_at ⇒ Object (readonly)
Returns the value of attribute repaid_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 12 def repaid_at @repaid_at end |
Instance Method Details
#accrue! ⇒ Object
30 31 32 33 34 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 30 def accrue! return if repaid? @accrued_interest = (@accrued_interest + (Constants::INTEREST_RATE * @principal)).round(10) end |
#age_seconds ⇒ Object
56 57 58 59 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 56 def age_seconds reference = @repaid_at || Time.now.utc (reference - @created_at).to_f end |
#repaid? ⇒ Boolean
44 45 46 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 44 def repaid? !@repaid_at.nil? end |
#repay!(amount: Constants::REPAYMENT_RATE) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 36 def repay!(amount: Constants::REPAYMENT_RATE) return if repaid? @accrued_interest = [0.0, @accrued_interest - amount].max.round(10) @principal = [0.0, @principal - amount].max.round(10) @repaid_at = Time.now.utc if @principal.zero? && @accrued_interest.zero? end |
#severity_label ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 48 def severity_label cost = total_cost Constants::SEVERITY_LABELS.each do |range, label| return label if range.cover?(cost) end :critical end |
#to_h ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 61 def to_h { id: @id, label: @label, debt_type: @debt_type, principal: @principal, accrued_interest: @accrued_interest, total_cost: total_cost, domain: @domain, severity: severity_label, age_seconds: age_seconds.round(2), created_at: @created_at.iso8601, repaid_at: @repaid_at&.iso8601, repaid: repaid? } end |
#total_cost ⇒ Object
26 27 28 |
# File 'lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb', line 26 def total_cost (@principal + @accrued_interest).round(10) end |