Class: TimeTracker::Month

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMonth

Returns a new instance of Month.



20
21
22
23
# File 'lib/time_tracker.rb', line 20

def initialize
  @entries = Array.new
  #@fixed_monthly_working_time      
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



15
16
17
# File 'lib/time_tracker.rb', line 15

def entries
  @entries
end

#fixed_monthly_working_timeObject

offset means +/- hours within this month global_offset within the whole year as a sum



18
19
20
# File 'lib/time_tracker.rb', line 18

def fixed_monthly_working_time
  @fixed_monthly_working_time
end

#global_offsetObject

offset means +/- hours within this month global_offset within the whole year as a sum



18
19
20
# File 'lib/time_tracker.rb', line 18

def global_offset
  @global_offset
end

#monthly_working_timeObject (readonly)

Returns the value of attribute monthly_working_time.



15
16
17
# File 'lib/time_tracker.rb', line 15

def monthly_working_time
  @monthly_working_time
end

#offsetObject

offset means +/- hours within this month global_offset within the whole year as a sum



18
19
20
# File 'lib/time_tracker.rb', line 18

def offset
  @offset
end

Instance Method Details

#add_event(event) ⇒ Object



25
26
27
# File 'lib/time_tracker.rb', line 25

def add_event event
  @entries.push(Entry.new(event))
end

#calulate_working_timeObject



33
34
35
36
37
38
39
40
# File 'lib/time_tracker.rb', line 33

def calulate_working_time 
  @monthly_working_time = 0
  @entries.each do |entry|
   @monthly_working_time += entry.duration	     
  end    	    
  @offset = @monthly_working_time - @fixed_monthly_working_time      
  @global_offset += @offset
end

#sort_entries!Object



29
30
31
# File 'lib/time_tracker.rb', line 29

def sort_entries!
  @entries.sort! { |a,b| a.start_time <=> b.start_time }
end

#to_sObject



42
43
44
45
46
47
48
# File 'lib/time_tracker.rb', line 42

def to_s
  entries = "Entries: \n"
  @entries.each do |entry|
    entries += "#{entry} \n"
  end
  entries
end