Class: Rbnotes::Statistics
- Inherits:
-
Object
- Object
- Rbnotes::Statistics
- Includes:
- Enumerable
- Defined in:
- lib/rbnotes/statistics.rb
Overview
Calculates statistics of the repository.
Defined Under Namespace
Classes: StatisticValue
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #each_year(&block) ⇒ Object
-
#initialize(conf) ⇒ Statistics
constructor
A new instance of Statistics.
- #monthly_report ⇒ Object
- #months(year) ⇒ Object
- #total_report ⇒ Object
- #yearly_report ⇒ Object
- #years ⇒ Object
Constructor Details
#initialize(conf) ⇒ Statistics
Returns a new instance of Statistics.
7 8 9 10 |
# File 'lib/rbnotes/statistics.rb', line 7 def initialize(conf) @repo = Textrepo.init(conf) @values = construct_values(@repo) end |
Instance Method Details
#each(&block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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(&block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# 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 ⇒ Object
23 24 25 26 27 28 |
# 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) ⇒ Object
50 51 52 |
# File 'lib/rbnotes/statistics.rb', line 50 def months(year) @values[year] || [] end |
#total_report ⇒ Object
12 13 14 |
# File 'lib/rbnotes/statistics.rb', line 12 def total_report puts @repo.entries.size end |
#yearly_report ⇒ Object
16 17 18 19 20 21 |
# 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 ⇒ Object
46 47 48 |
# File 'lib/rbnotes/statistics.rb', line 46 def years @values.keys end |