module Whydoiwork
Constants
- VERSION
Public Class Methods
config()
click to toggle source
# File lib/whydoiwork.rb, line 34 def self.config @config ||= YAML.load_file(config_file_name) end
config_file_exists?()
click to toggle source
# File lib/whydoiwork.rb, line 38 def self.config_file_exists? File.exists?(config_file_name) end
config_file_name()
click to toggle source
# File lib/whydoiwork.rb, line 42 def self.config_file_name File.expand_path("~/.whydoiwork.yml") end
config_sample()
click to toggle source
# File lib/whydoiwork.rb, line 46 def self.config_sample <<-YAML harvest: subdomain: username: password: rate: expenses: rent: 800 food: 1000 car: 250 YAML end
harvest()
click to toggle source
# File lib/whydoiwork.rb, line 66 def self.harvest @harvest ||= Harvest.client(config["harvest"]["subdomain"], config["harvest"]["username"], config["harvest"]["password"]) end
run()
click to toggle source
# File lib/whydoiwork.rb, line 9 def self.run unless config_file_exists? puts "Config file #{config_file_name} created." File.write(config_file_name, config_sample) exit 1 end money = (total_time_from_harvest * config["rate"]).round config["expenses"].each_pair do |name, cost| if money > cost puts "#{name} (#{cost})… done" elsif money > 0 puts "#{name} (#{cost})… earning right now" else puts "#{name} (#{cost})" end money -= cost end if money > 0 puts "Free to spend: #{money}" end end
total_time_from_harvest()
click to toggle source
# File lib/whydoiwork.rb, line 60 def self.total_time_from_harvest user_id = harvest.account.who_am_i.id time_entries = harvest.reports.time_by_user(user_id, Date.today.beginning_of_month, Date.today.end_of_month) time_entries.map(&:hours).inject(0, &:+) end