Class: Muon::Project
- Inherits:
-
Object
- Object
- Muon::Project
- Defined in:
- lib/muon/project.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #abort_tracking ⇒ Object
- #commit_entry(start_time, end_time) ⇒ Object
- #day_total_time(date = Time.now) ⇒ Object
- #goal ⇒ Object
- #goal=(seconds) ⇒ Object
- #goal_remaining_time ⇒ Object
- #has_goal? ⇒ Boolean
- #history_entries ⇒ Object
- #init_directory ⇒ Object
-
#initialize(path) ⇒ Project
constructor
A new instance of Project.
- #month_total_time(date = Time.now) ⇒ Object
- #name ⇒ Object
- #start_tracking(start_time = nil) ⇒ Object
- #stop_tracking(end_time = nil) ⇒ Object
- #tracking? ⇒ Boolean
- #tracking_duration ⇒ Object
- #working_dir ⇒ Object
Constructor Details
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/muon/project.rb', line 5 def path @path end |
Instance Method Details
#abort_tracking ⇒ Object
44 45 46 47 |
# File 'lib/muon/project.rb', line 44 def abort_tracking raise "Not tracking!" unless tracking_file_exists? delete_tracking_file end |
#commit_entry(start_time, end_time) ⇒ Object
53 54 55 56 |
# File 'lib/muon/project.rb', line 53 def commit_entry(start_time, end_time) entry = Entry.new(start_time, end_time) history.append(entry) end |
#day_total_time(date = Time.now) ⇒ Object
62 63 64 65 |
# File 'lib/muon/project.rb', line 62 def day_total_time(date = Time.now) date = date.strftime("%Y%m%d") history.entries.select { |e| e.start_time.strftime("%Y%m%d") == date }.map(&:duration).inject(&:+) end |
#goal ⇒ Object
76 77 78 |
# File 'lib/muon/project.rb', line 76 def goal read_goal_file.to_i end |
#goal=(seconds) ⇒ Object
80 81 82 |
# File 'lib/muon/project.rb', line 80 def goal=(seconds) write_goal_file(seconds.to_s) end |
#goal_remaining_time ⇒ Object
84 85 86 |
# File 'lib/muon/project.rb', line 84 def goal_remaining_time goal - month_total_time end |
#has_goal? ⇒ Boolean
72 73 74 |
# File 'lib/muon/project.rb', line 72 def has_goal? goal_file_exists? end |
#history_entries ⇒ Object
58 59 60 |
# File 'lib/muon/project.rb', line 58 def history_entries history.entries end |
#init_directory ⇒ Object
20 21 22 23 24 |
# File 'lib/muon/project.rb', line 20 def init_directory raise "Already initialized!" if Dir.exists?(working_dir) Dir.mkdir(working_dir) Dir.mkdir(File.join working_dir, "objects") end |
#month_total_time(date = Time.now) ⇒ Object
67 68 69 70 |
# File 'lib/muon/project.rb', line 67 def month_total_time(date = Time.now) date = date.strftime("%Y%m") history.entries.select { |e| e.start_time.strftime("%Y%m") == date }.map(&:duration).inject(&:+) end |
#name ⇒ Object
12 13 14 |
# File 'lib/muon/project.rb', line 12 def name File.basename(path) end |
#start_tracking(start_time = nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/muon/project.rb', line 30 def start_tracking(start_time = nil) raise "Already tracking!" if tracking_file_exists? start_time ||= Time.now create_tracking_file(start_time.to_s) end |
#stop_tracking(end_time = nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/muon/project.rb', line 36 def stop_tracking(end_time = nil) raise "Not tracking!" unless tracking_file_exists? start_time = Time.parse(read_tracking_file) end_time ||= Time.now commit_entry(start_time.to_s, end_time.to_s) delete_tracking_file end |
#tracking? ⇒ Boolean
26 27 28 |
# File 'lib/muon/project.rb', line 26 def tracking? File.exists?(File.join(working_dir, "current")) end |
#tracking_duration ⇒ Object
49 50 51 |
# File 'lib/muon/project.rb', line 49 def tracking_duration (Time.now - Time.parse(read_tracking_file)).to_i end |
#working_dir ⇒ Object
16 17 18 |
# File 'lib/muon/project.rb', line 16 def working_dir File.join(path, ".muon") end |