Class: RDist::Histogram

Inherits:
Object
  • Object
show all
Defined in:
lib/rdist/histogram.rb

Constant Summary collapse

DEFAULT_RANGE_UNIT_SIZE =
5
WHITESPACE =
' '.freeze
PERCENTAGE_MAX =
100

Instance Method Summary collapse

Constructor Details

#initialize(count_of, range_unit_size = DEFAULT_RANGE_UNIT_SIZE) ⇒ Histogram

Creates a new histogram from count_of. The keys of count_of are divided into some ranges by its count. The size of each range is specified with range_unit_size.



7
8
9
10
11
12
13
14
# File 'lib/rdist/histogram.rb', line 7

def initialize(count_of,
               range_unit_size=DEFAULT_RANGE_UNIT_SIZE)
  raise 'Initialized with illegal object' unless count_of
  @count_of = count_of
  @range_unit_size = range_unit_size
  init_count_in_range()
  init_cumulative_percentages()
end

Instance Method Details

#to_sObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/rdist/histogram.rb', line 19

def to_s
  str = ''
  @count_in_range.each_with_index do |count, range_id|
    str << heading_of(range_id)
    str << string_cumulative_percentage_at(range_id)
    str << string_count(count) << WHITESPACE
    str << bar(count) << NEWLINE
  end
  str << footer()
end