Class: SimpleStatistics::Data::Sample

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_statistics/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (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

#countObject



26
27
28
# File 'lib/simple_statistics/data.rb', line 26

def count
  @data.compact.size
end

#full?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/simple_statistics/data.rb', line 10

def full?
  not @data.any? { |s| s.nil? }
end

#maxObject



18
19
20
# File 'lib/simple_statistics/data.rb', line 18

def max
  @data.max
end

#meanObject



14
15
16
# File 'lib/simple_statistics/data.rb', line 14

def mean
  sum.to_f/count
end

#minObject



22
23
24
# File 'lib/simple_statistics/data.rb', line 22

def min
  @data.min
end

#sumObject



30
31
32
# File 'lib/simple_statistics/data.rb', line 30

def sum
  @data.compact.inject(0) { |r,v| r=r+v }
end