Class: Muon::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/muon/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Project

Returns a new instance of Project.



7
8
9
10
# File 'lib/muon/project.rb', line 7

def initialize(path)
  @path = path
  @history = History.new(working_dir)
end

Instance Attribute Details

#pathObject (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_trackingObject



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

#goalObject



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_timeObject



84
85
86
# File 'lib/muon/project.rb', line 84

def goal_remaining_time
  goal - month_total_time
end

#has_goal?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/muon/project.rb', line 72

def has_goal?
  goal_file_exists?
end

#history_entriesObject



58
59
60
# File 'lib/muon/project.rb', line 58

def history_entries
  history.entries
end

#init_directoryObject



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

#nameObject



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

Returns:

  • (Boolean)


26
27
28
# File 'lib/muon/project.rb', line 26

def tracking?
  File.exists?(File.join(working_dir, "current"))
end

#tracking_durationObject



49
50
51
# File 'lib/muon/project.rb', line 49

def tracking_duration
  (Time.now - Time.parse(read_tracking_file)).to_i
end

#working_dirObject



16
17
18
# File 'lib/muon/project.rb', line 16

def working_dir
  File.join(path, ".muon")
end