Class: Stan::Histogram
- Inherits:
-
Object
- Object
- Stan::Histogram
- Defined in:
- lib/stan/histogram.rb
Instance Attribute Summary collapse
-
#bin_size ⇒ Object
readonly
Returns the value of attribute bin_size.
-
#list ⇒ Object
readonly
Returns the value of attribute list.
Instance Method Summary collapse
-
#initialize(list, bin_size: nil) ⇒ Histogram
constructor
A new instance of Histogram.
- #to_a ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(list, bin_size: nil) ⇒ Histogram
Returns a new instance of Histogram.
5 6 7 8 |
# File 'lib/stan/histogram.rb', line 5 def initialize(list, bin_size: nil) @list = list @bin_size = bin_size end |
Instance Attribute Details
#bin_size ⇒ Object (readonly)
Returns the value of attribute bin_size.
3 4 5 |
# File 'lib/stan/histogram.rb', line 3 def bin_size @bin_size end |
#list ⇒ Object (readonly)
Returns the value of attribute list.
3 4 5 |
# File 'lib/stan/histogram.rb', line 3 def list @list end |
Instance Method Details
#to_a ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/stan/histogram.rb', line 10 def to_a @list.each_with_object({}) do |item, hash| bin = if bin_size.to_f > 0 (item.to_f / bin_size).round * bin_size else item end hash[bin] = hash[bin].to_i + 1 end.sort end |
#to_h ⇒ Object
23 24 25 |
# File 'lib/stan/histogram.rb', line 23 def to_h to_a.to_h end |