Class: Termplot::Widgets::Dataset
- Inherits:
-
Object
- Object
- Termplot::Widgets::Dataset
- Includes:
- Enumerable, Statistics
- Defined in:
- lib/termplot/widgets/dataset.rb
Instance Attribute Summary collapse
-
#capacity ⇒ Object
readonly
Returns the value of attribute capacity.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
- #<<(point) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(capacity) ⇒ Dataset
constructor
A new instance of Dataset.
- #set_capacity(capacity) ⇒ Object
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
#capacity ⇒ Object (readonly)
Returns the value of attribute capacity.
9 10 11 |
# File 'lib/termplot/widgets/dataset.rb', line 9 def capacity @capacity end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/termplot/widgets/dataset.rb', line 9 def data @data end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
9 10 11 |
# File 'lib/termplot/widgets/dataset.rb', line 9 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
9 10 11 |
# File 'lib/termplot/widgets/dataset.rb', line 9 def min @min end |
#range ⇒ Object (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
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 |