class Rbnotes::Statistics

Calculates statistics of the repository.

Public Class Methods

new(conf) click to toggle source
# File lib/rbnotes/statistics.rb, line 7
def initialize(conf)
  @repo = Textrepo.init(conf)
  @values = construct_values(@repo)
end

Public Instance Methods

each() { |year, mon, values| ... } click to toggle source
# File lib/rbnotes/statistics.rb, line 30
def each(&block)
  if block.nil?
    @values.map { |year, monthly_values|
      monthly_values.each { |mon, values|
        [year, mon, values]
      }
    }.to_enum(:each)
  else
    @values.each { |year, monthly_values|
      monthly_values.each { |mon, values|
        yield [year, mon, values]
      }
    }
  end
end
each_year() { |year, monthly_values| ... } click to toggle source
# File lib/rbnotes/statistics.rb, line 54
def each_year(&block)
  if block.nil?
    @values.map { |year, monthly_values|
      [year, monthly_values]
    }.to_enum(:each)
  else
    @values.each { |year, monthly_values|
      yield [year, monthly_values]
    }
  end
end
monthly_report() click to toggle source
# File lib/rbnotes/statistics.rb, line 23
def monthly_report
  self.each { |year, mon, values|
    num_of_notes = values.size
    puts "#{year}/#{mon}: #{num_of_notes}"
  }
end
months(year) click to toggle source
# File lib/rbnotes/statistics.rb, line 50
def months(year)
  @values[year] || []
end
total_report() click to toggle source
# File lib/rbnotes/statistics.rb, line 12
def total_report
  puts @repo.entries.size
end
yearly_report() click to toggle source
# File lib/rbnotes/statistics.rb, line 16
def yearly_report
  self.each_year { |year, monthly_values|
    num_of_notes = monthly_values.map { |_mon, values| values.size }.sum
    puts "#{year}: #{num_of_notes}"
  }
end
years() click to toggle source
# File lib/rbnotes/statistics.rb, line 46
def years
  @values.keys
end

Private Instance Methods

construct_values(repo) click to toggle source
# File lib/rbnotes/statistics.rb, line 68
def construct_values(repo)
  values = {}
  repo.each { |timestamp, text|
    value = StatisticValue.new(timestamp, text)
    y = value.year
    m = value.mon
    values[y] ||= {}
    values[y][m] ||= []

    values[y][m] << value
  }
  values
end