Module: Whydoiwork
- Defined in:
- lib/whydoiwork.rb,
lib/whydoiwork/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .config ⇒ Object
- .config_file_exists? ⇒ Boolean
- .config_file_name ⇒ Object
- .config_sample ⇒ Object
- .harvest ⇒ Object
- .run ⇒ Object
- .total_time_from_harvest ⇒ Object
Class Method Details
.config ⇒ Object
34 35 36 |
# File 'lib/whydoiwork.rb', line 34 def self.config @config ||= YAML.load_file(config_file_name) end |
.config_file_exists? ⇒ Boolean
38 39 40 |
# File 'lib/whydoiwork.rb', line 38 def self.config_file_exists? File.exists?(config_file_name) end |
.config_file_name ⇒ Object
42 43 44 |
# File 'lib/whydoiwork.rb', line 42 def self.config_file_name File.("~/.whydoiwork.yml") end |
.config_sample ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 ⇒ Object
66 67 68 |
# File 'lib/whydoiwork.rb', line 66 def self.harvest @harvest ||= Harvest.client(config["harvest"]["subdomain"], config["harvest"]["username"], config["harvest"]["password"]) end |
.run ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 ⇒ Object
60 61 62 63 64 |
# 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 |