Module: DebtCeiling

Extended by:
DebtCeiling
Included in:
DebtCeiling
Defined in:
lib/debt_ceiling.rb,
lib/debt_ceiling/debt.rb,
lib/debt_ceiling/version.rb,
lib/debt_ceiling/accounting.rb

Defined Under Namespace

Classes: Accounting, Debt

Constant Summary collapse

GRADE_MAP =

arbitrary default grades for now

{a: 0, b: 10, c: 20, d: 40, f: 100}
VERSION =
"0.0.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blacklistObject (readonly)

Returns the value of attribute blacklist.



63
64
65
# File 'lib/debt_ceiling.rb', line 63

def blacklist
  @blacklist
end

#ceiling_amountObject (readonly)

Returns the value of attribute ceiling_amount.



63
64
65
# File 'lib/debt_ceiling.rb', line 63

def ceiling_amount
  @ceiling_amount
end

#debtObject (readonly)

Returns the value of attribute debt.



63
64
65
# File 'lib/debt_ceiling.rb', line 63

def debt
  @debt
end

#reduction_dateObject (readonly)

Returns the value of attribute reduction_date.



63
64
65
# File 'lib/debt_ceiling.rb', line 63

def reduction_date
  @reduction_date
end

#reduction_targetObject (readonly)

Returns the value of attribute reduction_target.



63
64
65
# File 'lib/debt_ceiling.rb', line 63

def reduction_target
  @reduction_target
end

#whitelistObject (readonly)

Returns the value of attribute whitelist.



63
64
65
# File 'lib/debt_ceiling.rb', line 63

def whitelist
  @whitelist
end

Instance Method Details

#blacklist_matching(matchers) ⇒ Object



33
34
35
# File 'lib/debt_ceiling.rb', line 33

def blacklist_matching(matchers)
  @blacklist = matchers.map {|matcher| Regexp.new(matcher)}
end

#calculate(dir = ".") ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/debt_ceiling.rb', line 8

def calculate(dir=".")
  if File.exists?(Dir.pwd + '/.debt_ceiling')
     File.open(Dir.pwd + "/.debt_ceiling") {|f| DebtCeiling.module_eval(f.read)}
  elsif File.exists?(Dir.home + '/.debt_ceiling')
     File.open(Dir.home + '/.debt_ceiling') {|f| DebtCeiling.module_eval(f.read)}
  else
    puts "No .debt_ceiling configuration file detected in #{Dir.pwd} or ~/, using defaults"
  end

  extension_path = DebtCeiling.current_extension_file_path
  load extension_path if extension_path && File.exists?(extension_path)

  @debt = DebtCeiling::Accounting.calculate(dir)
  evaluate
end

#current_extension_file_pathObject



29
30
31
# File 'lib/debt_ceiling.rb', line 29

def current_extension_file_path
  @extension_file_path
end

#debt_reduction_target_and_date(target_value, date_to_parse) ⇒ Object



45
46
47
48
# File 'lib/debt_ceiling.rb', line 45

def debt_reduction_target_and_date(target_value, date_to_parse)
  @reduction_target = target_value
  @reduction_date   = Chronic.parse(date_to_parse)
end

#evaluateObject



50
51
52
53
54
55
56
57
# File 'lib/debt_ceiling.rb', line 50

def evaluate
  if ceiling_amount && ceiling_amount <= debt
    fail_test
  elsif reduction_target && reduction_target <= debt && 
        Time.now > reduction_date
    fail_test
  end
end

#extension_file_path(path) ⇒ Object



25
26
27
# File 'lib/debt_ceiling.rb', line 25

def extension_file_path(path)
  @extension_file_path = path
end

#fail_testObject



59
60
61
# File 'lib/debt_ceiling.rb', line 59

def fail_test
  Kernel.exit 1
end

#set_debt_ceiling(value) ⇒ Object



41
42
43
# File 'lib/debt_ceiling.rb', line 41

def set_debt_ceiling(value)
  @ceiling_amount = value
end

#whitelist_matching(matchers) ⇒ Object



37
38
39
# File 'lib/debt_ceiling.rb', line 37

def whitelist_matching(matchers)
  @whitelist =  matchers.map {|matcher| Regexp.new(matcher)}
end