Rename Preprocessing to DSVReader

* DSV stands for Delimiter-separated values.
* Preprocessing is too vague.
This commit is contained in:
kojix2
2020-11-25 17:19:07 +09:00
parent ccf232a742
commit 1a3ad9553c
4 changed files with 9 additions and 27 deletions

View File

@@ -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

View File

@@ -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