Class: Statistic

Inherits:
Object
  • Object
show all
Defined in:
lib/terrimporter/statistic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatistic

Returns a new instance of Statistic.



4
5
6
7
# File 'lib/terrimporter/statistic.rb', line 4

def initialize
  @header = ["---SUMMARY Date: #{Time.now.strftime("%d.%m.%Y %H:%M:%S")}" ]
  self.statistics = {}
end

Instance Attribute Details

#statisticsObject

Returns the value of attribute statistics.



2
3
4
# File 'lib/terrimporter/statistic.rb', line 2

def statistics
  @statistics
end

#timesObject

Returns the value of attribute times.



2
3
4
# File 'lib/terrimporter/statistic.rb', line 2

def times
  @times
end

Instance Method Details

#add(type) ⇒ Object



14
15
16
17
# File 'lib/terrimporter/statistic.rb', line 14

def add(type)
  init_data(type)
  self.statistics[type][:count] += 1
end

#add_message(type, message) ⇒ Object



9
10
11
12
# File 'lib/terrimporter/statistic.rb', line 9

def add_message(type, message)
  init_data(type)
  self.statistics[type][:message] = message
end

#init_data(type) ⇒ Object



19
20
21
# File 'lib/terrimporter/statistic.rb', line 19

def init_data(type)
  self.statistics[type] = {:count => 0, :message => ""} if self.statistics[type].nil?
end


23
24
25
26
27
28
29
30
31
# File 'lib/terrimporter/statistic.rb', line 23

def print_summary
  @header.each do |h|
    puts h
  end
  self.statistics.each do |key, value|

    puts "* %3s : %s" % [value[:count], value[:message]] unless value[:count] == 0
  end
end