summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-05-22 19:23:49 -0600
committermo khan <mo@mokhan.ca>2014-05-22 19:23:49 -0600
commit7dabcb337648a7bbd564940f2cb6d4fff89f8882 (patch)
tree5e520ad8fccd0479975c0f0ae09a0ff1b766556c
parentc5de286ead6b16f5eff9a97df1ecb2925ac673a1 (diff)
wip: vesting schedule.
-rw-r--r--lib/clock.rb5
-rw-r--r--lib/employee.rb55
-rw-r--r--lib/unit.rb9
-rw-r--r--spec/spec_helper.rb1
-rw-r--r--spec/unit/employee_spec.rb7
5 files changed, 71 insertions, 6 deletions
diff --git a/lib/clock.rb b/lib/clock.rb
new file mode 100644
index 0000000..41ccc77
--- /dev/null
+++ b/lib/clock.rb
@@ -0,0 +1,5 @@
+class Clock
+ def self.today
+ Date.today
+ end
+end
diff --git a/lib/employee.rb b/lib/employee.rb
index 97b1808..b29c5be 100644
--- a/lib/employee.rb
+++ b/lib/employee.rb
@@ -1,16 +1,65 @@
class Employee
def initialize
- @unvested_units = []
+ #@unvested_units = []
+ @grants = []
end
def issue_grant(value_of_grant, share_price)
+ #number_of_units = value_of_grant / share_price
+ #@unvested_units = [Unit.new] * number_of_units
+ @grants.push(Grant.new(value_of_grant, share_price))
+ end
+
+ def value_of_unvested_units_at(price)
+ @grants.inject(0.00.dollars) do |memo, grant|
+ memo + grant.value_of_unvested_units_at(price)
+ end
+ end
+
+ def grant_for(date)
+ @grants.find { |grant| grant.issued_at == date }
+ end
+end
+
+class Grant
+ attr_reader :issued_at
+
+ def initialize(value_of_grant, share_price, date = Clock.today)
number_of_units = value_of_grant / share_price
- @unvested_units = [Unit.new] * number_of_units
+ @units = [Unit.new] * number_of_units
+ @issued_at = date
end
def value_of_unvested_units_at(price)
- @unvested_units.inject(0.00.dollars) do |memo, unit|
+ unvested_units.inject(0.00.dollars) do |memo, unit|
+ memo + (unit * price)
+ end
+ end
+
+ def vest_at(price, portion)
+ number_of_units_to_vest = portion.to_f * @units.count
+ units_to_vest = @units.take(number_of_units_to_vest)
+ units_to_vest.each do |unit|
+ unit.vest_at(price)
+ end
+ puts unvested_units.count
+ puts vested_units.count
+ puts @units.count
+ end
+
+ private
+
+ def value_of(units, price)
+ units.inject(0.00.dollars) do |memo, unit|
memo + (unit * price)
end
end
+
+ def unvested_units
+ @units - vested_units
+ end
+
+ def vested_units
+ @units.find_all { |x| x.vested? }
+ end
end
diff --git a/lib/unit.rb b/lib/unit.rb
index 632ea95..0761c8e 100644
--- a/lib/unit.rb
+++ b/lib/unit.rb
@@ -2,4 +2,13 @@ class Unit
def *(price)
price
end
+
+ def vest_at(price)
+ @vested = true
+ @vesting_price = price
+ end
+
+ def vested?
+ @vested
+ end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 530ca88..3057259 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -6,4 +6,5 @@ require 'money'
require 'float'
require 'employee'
require 'unit'
+require 'clock'
diff --git a/spec/unit/employee_spec.rb b/spec/unit/employee_spec.rb
index 2bc524b..d998c65 100644
--- a/spec/unit/employee_spec.rb
+++ b/spec/unit/employee_spec.rb
@@ -12,10 +12,11 @@ describe Employee do
it "computes the value of the grant after one year" do
today = Clock.today
+ one_year_from_now = today + 365
sut.issue_grant(80_000, 1.00)
- Clock.stub(:now).and_return(1.year.from_now)
- sut.grant_for(today).vest_at(10.dollars)
- sut.unvested_units.value_at(10.dollars).should == 200_000
+ Clock.stub(:now).and_return(one_year_from_now)
+ sut.grant_for(today).vest_at(10.dollars, 1.0/4.0)
+ sut.value_of_unvested_units_at(10.dollars).should == 200_000.dollars
end
end
end