Class: Termplot::Series
- Inherits:
-
Object
- Object
- Termplot::Series
- Defined in:
- lib/termplot/series.rb
Constant Summary collapse
- DEFAULT_COLOR =
"red"
- DEFAULT_LINE_STYLE =
"line"
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#line_style ⇒ Object
readonly
Returns the value of attribute line_style.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#max_data_points ⇒ Object
Returns the value of attribute max_data_points.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #add_point(point) ⇒ Object
-
#initialize(max_data_points:, title: "Series", color: DEFAULT_COLOR, line_style: DEFAULT_LINE_STYLE) ⇒ Series
constructor
A new instance of Series.
Constructor Details
#initialize(max_data_points:, title: "Series", color: DEFAULT_COLOR, line_style: DEFAULT_LINE_STYLE) ⇒ Series
Returns a new instance of Series.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/termplot/series.rb', line 9 def initialize(max_data_points:, title: "Series", color: DEFAULT_COLOR, line_style: DEFAULT_LINE_STYLE) @data = [] @max_data_points = max_data_points @min = 0 @max = 0 @range = 0 @title = title @color = Termplot::Colors.fetch(color, DEFAULT_COLOR) @line_style = Termplot::CharacterMap::LINE_STYLES.fetch( line_style, Termplot::CharacterMap::LINE_STYLES[DEFAULT_LINE_STYLE] ) end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
3 4 5 |
# File 'lib/termplot/series.rb', line 3 def color @color end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/termplot/series.rb', line 3 def data @data end |
#line_style ⇒ Object (readonly)
Returns the value of attribute line_style.
3 4 5 |
# File 'lib/termplot/series.rb', line 3 def line_style @line_style end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
3 4 5 |
# File 'lib/termplot/series.rb', line 3 def max @max end |
#max_data_points ⇒ Object
Returns the value of attribute max_data_points.
4 5 6 |
# File 'lib/termplot/series.rb', line 4 def max_data_points @max_data_points end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
3 4 5 |
# File 'lib/termplot/series.rb', line 3 def min @min end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
3 4 5 |
# File 'lib/termplot/series.rb', line 3 def range @range end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/termplot/series.rb', line 3 def title @title end |
Instance Method Details
#add_point(point) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/termplot/series.rb', line 24 def add_point(point) @data.push(point) while @data.length > max_data_points do @data.shift end @min = data.min @max = data.max @range = (max - min).abs @range = 1 if range.zero? end |