Class: Termplot::Widgets::Dataset

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Statistics
Defined in:
lib/termplot/widgets/dataset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Statistics

#count, #mean, #standard_deviation

Constructor Details

#initialize(capacity) ⇒ Dataset

Returns a new instance of Dataset.



11
12
13
14
15
16
17
# File 'lib/termplot/widgets/dataset.rb', line 11

def initialize(capacity)
  @data = []
  @min = 0
  @max = 0
  @range = 0
  @capacity = capacity
end

Instance Attribute Details

#capacityObject (readonly)

Returns the value of attribute capacity.



9
10
11
# File 'lib/termplot/widgets/dataset.rb', line 9

def capacity
  @capacity
end

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/termplot/widgets/dataset.rb', line 9

def data
  @data
end

#maxObject (readonly)

Returns the value of attribute max.



9
10
11
# File 'lib/termplot/widgets/dataset.rb', line 9

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



9
10
11
# File 'lib/termplot/widgets/dataset.rb', line 9

def min
  @min
end

#rangeObject (readonly)

Returns the value of attribute range.



9
10
11
# File 'lib/termplot/widgets/dataset.rb', line 9

def range
  @range
end

Instance Method Details

#<<(point) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/termplot/widgets/dataset.rb', line 23

def << (point)
  data.push(point)

  discard_excess

  @min = data.min
  @max = data.max
  @range = (max - min).abs
  @range = 1 if range.zero?
end

#each(&block) ⇒ Object



19
20
21
# File 'lib/termplot/widgets/dataset.rb', line 19

def each(&block)
  data.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/termplot/widgets/dataset.rb', line 39

def empty?
  data.empty?
end

#set_capacity(capacity) ⇒ Object



34
35
36
37
# File 'lib/termplot/widgets/dataset.rb', line 34

def set_capacity(capacity)
  @capacity = capacity
  discard_excess
end