From 9e15c0ac2a8097face30611e8d63e67992b46fee Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Fri, 28 May 2021 10:06:58 +0900 Subject: [PATCH] Rename UnicodePlotBackend -> Backend::UnicodePlot --- ...nicode_plot_backend.rb => unicode_plot.rb} | 22 +++++++++---------- lib/youplot/command.rb | 4 ++-- test/youplot/simple_test.rb | 12 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-) rename lib/youplot/backends/{unicode_plot_backend.rb => unicode_plot.rb} (88%) diff --git a/lib/youplot/backends/unicode_plot_backend.rb b/lib/youplot/backends/unicode_plot.rb similarity index 88% rename from lib/youplot/backends/unicode_plot_backend.rb rename to lib/youplot/backends/unicode_plot.rb index 95a34e9..f99b878 100644 --- a/lib/youplot/backends/unicode_plot_backend.rb +++ b/lib/youplot/backends/unicode_plot.rb @@ -6,7 +6,7 @@ require 'unicode_plot' module YouPlot # plotting functions. module Backends - module UnicodePlotBackend + module UnicodePlot class Error < StandardError; end module_function @@ -39,7 +39,7 @@ module YouPlot labels = series[x_col] values = series[y_col].map(&:to_f) end - UnicodePlot.barplot(labels, values, **params.to_hc) + ::UnicodePlot.barplot(labels, values, **params.to_hc) end def histogram(data, params) @@ -47,7 +47,7 @@ module YouPlot series = data.series params.title ||= data.headers[0] if headers values = series[0].map(&:to_f) - UnicodePlot.histogram(values, **params.to_hc) + ::UnicodePlot.histogram(values, **params.to_hc) end def line(data, params, fmt = nil) @@ -57,7 +57,7 @@ module YouPlot # If there is only one series, it is assumed to be sequential data. params.ylabel ||= headers[0] if headers y = series[0].map(&:to_f) - UnicodePlot.lineplot(y, **params.to_hc) + ::UnicodePlot.lineplot(y, **params.to_hc) else # If there are 2 or more series... if fmt == 'yx' @@ -75,7 +75,7 @@ module YouPlot end x = series[x_col].map(&:to_f) y = series[y_col].map(&:to_f) - UnicodePlot.lineplot(x, y, **params.to_hc) + ::UnicodePlot.lineplot(x, y, **params.to_hc) end end @@ -94,9 +94,9 @@ module YouPlot end params.xlim ||= series[0].flatten.minmax # why need? params.ylim ||= series[1..-1].flatten.minmax # why need? - plot = UnicodePlot.public_send(method1, series[0], series[1], **params.to_hc) + plot = ::UnicodePlot.public_send(method1, series[0], series[1], **params.to_hc) 2.upto(series.size - 1) do |i| - UnicodePlot.public_send(method2, plot, series[0], series[i], name: headers&.[](i)) + ::UnicodePlot.public_send(method2, plot, series[0], series[i], name: headers&.[](i)) end plot end @@ -112,9 +112,9 @@ module YouPlot params.xlim ||= series2.map(&:first).flatten.minmax # why need? params.ylim ||= series2.map(&:last).flatten.minmax # why need? x1, y1 = series2.shift - plot = UnicodePlot.public_send(method1, x1, y1, **params.to_hc) + plot = ::UnicodePlot.public_send(method1, x1, y1, **params.to_hc) series2.each_with_index do |(xi, yi), i| - UnicodePlot.public_send(method2, plot, xi, yi, name: headers&.[]((i + 1) * 2)) + ::UnicodePlot.public_send(method2, plot, xi, yi, name: headers&.[]((i + 1) * 2)) end plot end @@ -152,13 +152,13 @@ module YouPlot series = data.series headers ||= (1..series.size).map(&:to_s) series.map! { |s| s.map(&:to_f) } - UnicodePlot.boxplot(headers, series, **params.to_hc) + ::UnicodePlot.boxplot(headers, series, **params.to_hc) end def colors(color_names = false) # FIXME s = String.new - UnicodePlot::StyledPrinter::TEXT_COLORS.each do |k, v| + ::UnicodePlot::StyledPrinter::TEXT_COLORS.each do |k, v| s << v s << k.to_s unless color_names diff --git a/lib/youplot/command.rb b/lib/youplot/command.rb index 2ceb4df..84497e6 100644 --- a/lib/youplot/command.rb +++ b/lib/youplot/command.rb @@ -4,7 +4,7 @@ require_relative 'dsv' require_relative 'parser' # FIXME -require_relative 'backends/unicode_plot_backend' +require_relative 'backends/unicode_plot' module YouPlot Data = Struct.new(:headers, :series) @@ -19,7 +19,7 @@ module YouPlot @command = nil @params = nil @options = nil - @backend = YouPlot::Backends::UnicodePlotBackend + @backend = YouPlot::Backends::UnicodePlot end def run_as_executable diff --git a/test/youplot/simple_test.rb b/test/youplot/simple_test.rb index 44fc3b1..1beb815 100644 --- a/test/youplot/simple_test.rb +++ b/test/youplot/simple_test.rb @@ -67,37 +67,37 @@ class YouPlotSimpleTest < Test::Unit::TestCase end test :lines do - assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do + assert_raise(YouPlot::Backends::UnicodePlot::Error) do YouPlot::Command.new(['lines']).run end end test :lineplots do - assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do + assert_raise(YouPlot::Backends::UnicodePlot::Error) do YouPlot::Command.new(['lineplots']).run end end test :s do - assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do + assert_raise(YouPlot::Backends::UnicodePlot::Error) do YouPlot::Command.new(['s']).run end end test :scatter do - assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do + assert_raise(YouPlot::Backends::UnicodePlot::Error) do YouPlot::Command.new(['scatter']).run end end test :d do - assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do + assert_raise(YouPlot::Backends::UnicodePlot::Error) do YouPlot::Command.new(['d']).run end end test :density do - assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do + assert_raise(YouPlot::Backends::UnicodePlot::Error) do YouPlot::Command.new(['density']).run end end