Module: Notes::Stats

Extended by:
Stats
Included in:
Stats
Defined in:
lib/notes-cli/stats.rb

Instance Method Summary collapse

Instance Method Details

#compute(tasks) ⇒ Object



7
8
9
10
11
12
# File 'lib/notes-cli/stats.rb', line 7

def compute(tasks)
  {
    flag_counts: flag_counts(tasks),
    found_flags: found_flags(tasks)
  }
end

#flag_counts(tasks) ⇒ Object

Take in a set of tasks and compute aggregate stats such as counts per flag. Intended to augment a JSON set

tasks: Array

Returns Hash



20
21
22
23
24
25
26
# File 'lib/notes-cli/stats.rb', line 20

def flag_counts(tasks)
  counts = Hash.new(0)
  tasks.each do |task|
    task.flags.each { |flag| counts[flag] += 1 }
  end
  counts
end

#found_flags(tasks) ⇒ Object

Compute the distinct flags found in a a set of tasks

tasks: Array

Returns Array of flag names



33
34
35
36
37
# File 'lib/notes-cli/stats.rb', line 33

def found_flags(tasks)
  flags = Set.new
  tasks.each { |task| flags.merge(task.flags) }
  flags.to_a
end