Class: RDist::Histogram
- Inherits:
-
Object
- Object
- RDist::Histogram
- Defined in:
- lib/rdist/histogram.rb
Constant Summary collapse
- DEFAULT_RANGE_UNIT_SIZE =
5- WHITESPACE =
' '.freeze
- PERCENTAGE_MAX =
100
Instance Method Summary collapse
-
#initialize(count_of, range_unit_size = DEFAULT_RANGE_UNIT_SIZE) ⇒ Histogram
constructor
Creates a new histogram from
count_of. - #to_s ⇒ Object
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_s ⇒ Object
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 << (count) << NEWLINE end str << () end |