Move Plot::Params to Parameters

This commit is contained in:
kojix2 2021-05-27 21:15:06 +09:00
parent 54b70f1f27
commit 7c42d9a444
4 changed files with 37 additions and 39 deletions

View File

@ -3,6 +3,7 @@
require 'unicode_plot'
require 'youplot/version'
require 'youplot/dsv'
require 'youplot/parameters'
require 'youplot/command'
module YouPlot

View File

@ -2,7 +2,6 @@
require 'optparse'
require_relative 'options'
require_relative 'plot_params'
module YouPlot
class Command
@ -28,7 +27,7 @@ module YouPlot
debug: false
)
@params = PlotParams.new
@params = Parameters.new
end
def create_default_parser

View File

@ -1,37 +0,0 @@
# frozen_string_literal: true
module YouPlot
class Command
# UnicodePlot parameters.
# * Normally in a Ruby program, you might use hash for the parameter object.
# * Here, I use Struct for 2 safety reason.
# * The keys are static in Struct.
# * Struct does not conflict with keyword arguments. Hash dose.
PlotParams = Struct.new(
# Sort me!
:title,
:width,
:height,
:border,
:margin,
:padding,
:color,
:xlabel,
:ylabel,
:labels,
:symbol,
:xscale,
:nbins,
:closed,
:canvas,
:xlim,
:ylim,
:grid,
:name
) do
def to_hc
to_h.compact
end
end
end
end

35
lib/youplot/parameters.rb Normal file
View File

@ -0,0 +1,35 @@
# frozen_string_literal: true
module YouPlot
# UnicodePlot parameters.
# * Normally in a Ruby program, you might use hash for the parameter object.
# * Here, I use Struct for 2 safety reason.
# * The keys are static in Struct.
# * Struct does not conflict with keyword arguments. Hash dose.
Parameters = Struct.new(
# Sort me!
:title,
:width,
:height,
:border,
:margin,
:padding,
:color,
:xlabel,
:ylabel,
:labels,
:symbol,
:xscale,
:nbins,
:closed,
:canvas,
:xlim,
:ylim,
:grid,
:name
) do
def to_hc
to_h.compact
end
end
end