Module: MiniHistogram::MiniUnicodePlot::ValueTransformer
- Included in:
- Barplot
- Defined in:
- lib/mini_histogram/plot.rb
Constant Summary collapse
- PREDEFINED_TRANSFORM_FUNCTIONS =
{ log: Math.method(:log), ln: Math.method(:log), log10: Math.method(:log10), lg: Math.method(:log10), log2: Math.method(:log2), lb: Math.method(:log2), }.freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.transform_name(func, basename = "") ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/mini_histogram/plot.rb', line 218 module_function def transform_name(func, basename="") return basename unless func case func when String, Symbol name = func when ->(f) { f.respond_to?(:name) } name = func.name else name = "custom" end "#{basename} [#{name}]" end |
Instance Method Details
#transform_values(func, values) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/mini_histogram/plot.rb', line 200 def transform_values(func, values) return values unless func unless func.respond_to?(:call) func = PREDEFINED_TRANSFORM_FUNCTIONS[func] unless func.respond_to?(:call) raise ArgumentError, "func must be callable" end end case values when Numeric func.(values) else values.map(&func) end end |