Class: SimpleStatistics::Data::Sample
- Inherits:
-
Object
- Object
- SimpleStatistics::Data::Sample
- Defined in:
- lib/simple_statistics/data.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #count ⇒ Object
- #full? ⇒ Boolean
-
#initialize(data) ⇒ Sample
constructor
A new instance of Sample.
- #max ⇒ Object
- #mean ⇒ Object
- #min ⇒ Object
- #sum ⇒ Object
Constructor Details
#initialize(data) ⇒ Sample
Returns a new instance of Sample.
6 7 8 |
# File 'lib/simple_statistics/data.rb', line 6 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/simple_statistics/data.rb', line 4 def data @data end |
Instance Method Details
#count ⇒ Object
26 27 28 |
# File 'lib/simple_statistics/data.rb', line 26 def count @data.compact.size end |
#full? ⇒ Boolean
10 11 12 |
# File 'lib/simple_statistics/data.rb', line 10 def full? not @data.any? { |s| s.nil? } end |
#max ⇒ Object
18 19 20 |
# File 'lib/simple_statistics/data.rb', line 18 def max @data.max end |
#mean ⇒ Object
14 15 16 |
# File 'lib/simple_statistics/data.rb', line 14 def mean sum.to_f/count end |
#min ⇒ Object
22 23 24 |
# File 'lib/simple_statistics/data.rb', line 22 def min @data.min end |
#sum ⇒ Object
30 31 32 |
# File 'lib/simple_statistics/data.rb', line 30 def sum @data.compact.inject(0) { |r,v| r=r+v } end |