Class: DebtCeiling::Debt
- Inherits:
-
Object
- Object
- DebtCeiling::Debt
- Defined in:
- lib/debt_ceiling/debt.rb
Constant Summary collapse
- DoNotWhitelistAndBlacklistSimulateneously =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#analysed_module ⇒ Object
readonly
Returns the value of attribute analysed_module.
-
#debt_amount ⇒ Object
Returns the value of attribute debt_amount.
-
#file_attributes ⇒ Object
readonly
Returns the value of attribute file_attributes.
-
#linecount ⇒ Object
readonly
Returns the value of attribute linecount.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #default_measure_debt ⇒ Object
-
#initialize(file_attributes) ⇒ Debt
constructor
A new instance of Debt.
- #to_i ⇒ Object
- #valid_debt? ⇒ Boolean
Constructor Details
#initialize(file_attributes) ⇒ Debt
Returns a new instance of Debt.
7 8 9 10 11 12 13 14 |
# File 'lib/debt_ceiling/debt.rb', line 7 def initialize(file_attributes) @file_attributes = file_attributes @path = file_attributes.path @analysed_module = file_attributes.analysed_module @module_name = file_attributes.name @linecount = file_attributes.linecount default_measure_debt if valid_debt? end |
Instance Attribute Details
#analysed_module ⇒ Object (readonly)
Returns the value of attribute analysed_module.
5 6 7 |
# File 'lib/debt_ceiling/debt.rb', line 5 def analysed_module @analysed_module end |
#debt_amount ⇒ Object
Returns the value of attribute debt_amount.
6 7 8 |
# File 'lib/debt_ceiling/debt.rb', line 6 def debt_amount @debt_amount end |
#file_attributes ⇒ Object (readonly)
Returns the value of attribute file_attributes.
5 6 7 |
# File 'lib/debt_ceiling/debt.rb', line 5 def file_attributes @file_attributes end |
#linecount ⇒ Object (readonly)
Returns the value of attribute linecount.
5 6 7 |
# File 'lib/debt_ceiling/debt.rb', line 5 def linecount @linecount end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
5 6 7 |
# File 'lib/debt_ceiling/debt.rb', line 5 def module_name @module_name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/debt_ceiling/debt.rb', line 5 def path @path end |
Class Method Details
.blacklist_includes?(debt) ⇒ Boolean
46 47 48 |
# File 'lib/debt_ceiling/debt.rb', line 46 def self.blacklist_includes?(debt) DebtCeiling.blacklist.detect {|filename| filename.match debt.path } end |
.whitelist_includes?(debt) ⇒ Boolean
42 43 44 |
# File 'lib/debt_ceiling/debt.rb', line 42 def self.whitelist_includes?(debt) DebtCeiling.whitelist.detect {|filename| filename.match debt.path } end |
Instance Method Details
#+(other) ⇒ Object
54 55 56 |
# File 'lib/debt_ceiling/debt.rb', line 54 def +(other) self.to_i + other.to_i end |
#default_measure_debt ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/debt_ceiling/debt.rb', line 16 def default_measure_debt if self.respond_to?(:measure_debt) cost = self.public_send(:measure_debt) end if !cost cost = if self.respond_to?(:augment_debt) self.public_send(:augment_debt) || 0 else 0 end letter_grade = file_attributes.analysed_module..to_s.downcase cost_per_line = DebtCeiling.public_send("#{letter_grade}_current_cost_per_line") cost += file_attributes.linecount * cost_per_line end self.debt_amount = cost end |
#to_i ⇒ Object
50 51 52 |
# File 'lib/debt_ceiling/debt.rb', line 50 def to_i debt_amount.to_i end |
#valid_debt? ⇒ Boolean
33 34 35 36 37 38 39 40 |
# File 'lib/debt_ceiling/debt.rb', line 33 def valid_debt? black_empty = DebtCeiling.blacklist.empty? white_empty = DebtCeiling.whitelist.empty? raise DoNotWhitelistAndBlacklistSimulateneously if (!black_empty && !white_empty) (black_empty && white_empty) || (black_empty && self.class.whitelist_includes?(self)) || (white_empty && !self.class.blacklist_includes?(self)) end |