Class: UnicodePlot::StringStemplot
- Defined in:
- src/lib/unicode_plot/stemplot.rb
Class Method Summary collapse
-
.sorted_stem_list(stems, all: true) ⇒ Array
Used when we have stems from a back-to-back stemplot and a combined list of stems is given.
Instance Method Summary collapse
-
#initialize(vector, scale: 10, string_padchar: '_', **_kw) ⇒ StringStemplot
constructor
A new instance of StringStemplot.
-
#print_key(_scale, _divider) ⇒ false
Function prototype to provide same interface as NumericStemplot.
Methods inherited from Stemplot
factory, #insert, #leaves, #max_stem_length, #raw_stems, #stems
Constructor Details
#initialize(vector, scale: 10, string_padchar: '_', **_kw) ⇒ StringStemplot
Returns a new instance of StringStemplot.
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'src/lib/unicode_plot/stemplot.rb', line 186 def initialize(vector, scale: 10, string_padchar: '_', **_kw) super stem_places = Math.log10(scale).floor raise ArgumentError, "Cannot take fewer than 1 place from stem. Scale parameter should be greater than or equal to 10." if stem_places < 1 vector.each do |value| # Strings may be shorter than the number of places we desire, # so we will pad them with a string-pad-character. padded_value = value.ljust(stem_places+1, string_padchar) stem = padded_value[0...stem_places] leaf = padded_value[stem_places] self.insert(stem, leaf) end end |
Class Method Details
.sorted_stem_list(stems, all: true) ⇒ Array
Used when we have stems from a back-to-back stemplot and a combined list of stems is given
212 213 214 215 216 217 218 219 |
# File 'src/lib/unicode_plot/stemplot.rb', line 212 def self.sorted_stem_list(stems, all: true) if all rmin, rmax = stems.minmax return (rmin .. rmax).to_a else stems.sort end end |
Instance Method Details
#print_key(_scale, _divider) ⇒ false
Function prototype to provide same interface as NumericStemplot.
This function does not do anything.
203 204 205 206 |
# File 'src/lib/unicode_plot/stemplot.rb', line 203 def print_key(_scale, _divider) # intentionally empty return false end |