Sha256: 4e1f8b2b410452d818526869fe79712b4f90ae804b3ad9d14c8d86987dcf42fd

Contents?: true

Size: 819 Bytes

Versions: 2

Compression:

Stored size: 819 Bytes

Contents

require 'set'

module Notes
  module Stats
    extend self

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

    # Take in a set of tasks and compute aggregate stats such as counts per
    # flag. Intended to augment a JSON set
    #
    # tasks: Array[Notes::Task]
    #
    # Returns Hash
    def flag_counts(tasks)
      counts = Hash.new(0)
      tasks.each do |task|
        task.flags.each { |flag| counts[flag] += 1 }
      end
      counts
    end

    # Compute the distinct flags found in a a set of tasks
    #
    # tasks: Array[Notes::Task]
    #
    # Returns Array[String] of flag names
    def found_flags(tasks)
      flags = Set.new
      tasks.each { |task| flags.merge(task.flags) }
      flags.to_a
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
notes-cli-2.0.1 lib/notes-cli/stats.rb
notes-cli-2.0.0 lib/notes-cli/stats.rb