From 1a3ad9553c3e434de292f382e5465b8d43c84200 Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Wed, 25 Nov 2020 17:19:07 +0900 Subject: [PATCH] Rename Preprocessing to DSVReader * DSV stands for Delimiter-separated values. * Preprocessing is too vague. --- lib/youplot.rb | 2 +- lib/youplot/command.rb | 6 +++--- .../{preprocessing.rb => dsv_reader.rb} | 19 +++---------------- .../dev_reader_test.rb} | 9 ++------- 4 files changed, 9 insertions(+), 27 deletions(-) rename lib/youplot/{preprocessing.rb => dsv_reader.rb} (80%) rename test/{uplot/preprocessing_test.rb => youplot/dev_reader_test.rb} (94%) diff --git a/lib/youplot.rb b/lib/youplot.rb index 78f0bad..831c4e4 100644 --- a/lib/youplot.rb +++ b/lib/youplot.rb @@ -2,7 +2,7 @@ require 'unicode_plot' require 'youplot/version' -require 'youplot/preprocessing' +require 'youplot/dsv_reader' require 'youplot/command' module YouPlot diff --git a/lib/youplot/command.rb b/lib/youplot/command.rb index ff2383d..62e574e 100644 --- a/lib/youplot/command.rb +++ b/lib/youplot/command.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'preprocessing' +require_relative 'dsv_reader' require_relative 'command/parser' # FIXME @@ -55,9 +55,9 @@ module YouPlot @data = if @encoding input2 = input.dup.force_encoding(@encoding).encode('utf-8') - Preprocessing.input(input2, delimiter, headers, transpose) + DSVReader.input(input2, delimiter, headers, transpose) else - Preprocessing.input(input, delimiter, headers, transpose) + DSVReader.input(input, delimiter, headers, transpose) end pp @data if @debug diff --git a/lib/youplot/preprocessing.rb b/lib/youplot/dsv_reader.rb similarity index 80% rename from lib/youplot/preprocessing.rb rename to lib/youplot/dsv_reader.rb index ce67d90..a338296 100644 --- a/lib/youplot/preprocessing.rb +++ b/lib/youplot/dsv_reader.rb @@ -3,9 +3,10 @@ require 'csv' module YouPlot - module Preprocessing + # Read and interpret Delimiter-separated values format file or stream. + module DSVReader module_function - + def input(input, delimiter, headers, transpose) arr = parse_as_csv(input, delimiter) headers = get_headers(arr, headers, transpose) @@ -68,19 +69,5 @@ module YouPlot transpose2(arr) end end - - def count_values(arr) - # tally was added in Ruby 2.7 - if Enumerable.method_defined? :tally - arr.tally - else - # https://github.com/marcandre/backports - arr.each_with_object(Hash.new(0)) { |item, res| res[item] += 1 } - .tap { |h| h.default = nil } - end - .sort { |a, b| a[1] <=> b[1] } - .reverse - .transpose - end end end diff --git a/test/uplot/preprocessing_test.rb b/test/youplot/dev_reader_test.rb similarity index 94% rename from test/uplot/preprocessing_test.rb rename to test/youplot/dev_reader_test.rb index 8506820..f448250 100644 --- a/test/uplot/preprocessing_test.rb +++ b/test/youplot/dev_reader_test.rb @@ -2,9 +2,9 @@ require_relative '../test_helper' -class YouPlotPreprocessingTest < Test::Unit::TestCase +class YouPlotDSVReaderTest < Test::Unit::TestCase def setup - @m = YouPlot::Preprocessing + @m = YouPlot::DSVReader end test :transpose2 do @@ -124,9 +124,4 @@ class YouPlotPreprocessingTest < Test::Unit::TestCase [2, 4], [3, 5, 6]], false, false)) end - - test :count_values do - assert_equal([%i[a b c], [3, 2, 1]], @m.count_values(%i[a a a b b c])) - assert_equal([%i[c b a], [3, 2, 1]], @m.count_values(%i[a b b c c c])) - end end