Class: Versed::Category

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, date_range) ⇒ Category

Returns a new instance of Category.



7
8
9
10
11
# File 'lib/versed/category.rb', line 7

def initialize(id, date_range)
  @id = id
  @tasks = []
  date_range.each { |date| @tasks << Task.new(id, date) }
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/versed/category.rb', line 5

def id
  @id
end

#tasksObject (readonly)

Returns the value of attribute tasks.



5
6
7
# File 'lib/versed/category.rb', line 5

def tasks
  @tasks
end

Instance Method Details

#incomplete?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/versed/category.rb', line 13

def incomplete?
  total_min_incomplete > 0
end

#percent_incompleteObject



40
41
42
# File 'lib/versed/category.rb', line 40

def percent_incomplete
  ((total_min_incomplete / total_min_scheduled.to_f) * 100).round(1)
end

#total_min_incompleteObject



35
36
37
38
# File 'lib/versed/category.rb', line 35

def total_min_incomplete
  incomplete = total_min_scheduled - total_min_logged
  incomplete >= 0 ? incomplete : 0
end

#total_min_loggedObject



26
27
28
29
30
31
32
33
# File 'lib/versed/category.rb', line 26

def total_min_logged
  logged = 0
  @tasks.each do |task|
    next unless task.time_spent
    logged += task.time_spent
  end
  logged
end

#total_min_scheduledObject



17
18
19
20
21
22
23
24
# File 'lib/versed/category.rb', line 17

def total_min_scheduled
  scheduled = 0
  @tasks.each do |task|
    next unless task.time_scheduled
    scheduled += task.time_scheduled
  end
  scheduled
end