Created
April 2, 2014 06:42
-
-
Save csgavino/9929020 to your computer and use it in GitHub Desktop.
Shows you how much money you're wasting in this meeting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
class Clock | |
def initialize(minutes = 0) | |
@minutes = minutes | |
@cost = 0 | |
end | |
def work_days; 22 end | |
def average_salary; 4000.0 end | |
def work_hours; 8 end | |
def hourly_rate(person = 1) | |
(average_salary/work_days/work_hours) * person | |
end | |
def minute_rate(person = 1) | |
(hourly_rate/60) * person | |
end | |
def running_cost(person) | |
(minute_rate(person) * @minutes).round(2) | |
end | |
def minutes; @minutes end | |
def tick | |
@minutes+=1 | |
end | |
def self.start(person) | |
clock = Clock.new | |
while true do | |
system 'clear' | |
puts "We've been here for #{clock.minutes} minutes and it has cost us $#{clock.running_cost(person)}" | |
clock.tick | |
sleep 60 | |
end | |
end | |
end | |
# Clock.start 1 | |
describe Clock do | |
it 'assumes that there are 22 working days in a month' do | |
subject.work_days.should == 22 | |
end | |
it 'assumes that the average salary is 4000 a month' do | |
subject.average_salary.should == 4000.0 | |
end | |
it 'assumes that people work for 8 hours a day' do | |
subject.work_hours.should == 8 | |
end | |
it 'computes how much a person earns per hour' do | |
subject.hourly_rate.should == hourly_rate | |
end | |
it 'computes how much this meeting costs given 1 person' do | |
subject.minute_rate(1).should == minute_rate | |
end | |
it 'computes how much this meeting costs given 2 person' do | |
subject.minute_rate(2).should == (minute_rate) * 2 | |
end | |
it 'knows the running cost given the # of minutes given 1 persons' do | |
Clock.new(5).running_cost(1).should == (minute_rate * 1 * 5).round(2) | |
end | |
it 'knows the running cost given the # of minutes given 2 persons' do | |
Clock.new(5).running_cost(2).should == (minute_rate * 2 * 5).round(2) | |
end | |
def hourly_rate | |
4000.0/22/8 | |
end | |
def minute_rate | |
hourly_rate/60 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment