From b484a3a96f02fb8ee97b0245d06edf8e890864c2 Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Sat, 29 May 2021 11:19:48 +0900 Subject: [PATCH] Refactor parser --- lib/youplot/parser.rb | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/youplot/parser.rb b/lib/youplot/parser.rb index 2c90c4c..5d8323d 100644 --- a/lib/youplot/parser.rb +++ b/lib/youplot/parser.rb @@ -186,6 +186,22 @@ module YouPlot end end + def sub_parser_add_fmt_xyxy + sub_parser.on_head('--fmt STR', String, + 'xyxy : header is like x1, y1, x2, y2, x3, y3...', + 'xyy : header is like x, y1, y2, y2, y3...') do |v| + options[:fmt] = v + end + end + + def sub_parser_add_fmt_yx + sub_parser.on_head('--fmt STR', String, + 'xy : header is like x, y...', + 'yx : header is like y, x...') do |v| + options[:fmt] = v + end + end + def create_sub_parser @sub_parser = create_base_parser sub_parser.banner = \ @@ -206,9 +222,7 @@ module YouPlot when :barplot, :bar sub_parser_add_symbol - sub_parser.on_head('--fmt STR', String, 'xy : header is like x, y...', 'yx : header is like y, x...') do |v| - options[:fmt] = v - end + sub_parser_add_fmt_yx sub_parser_add_xscale when :count, :c @@ -227,39 +241,28 @@ module YouPlot when :lineplot, :line sub_parser_add_canvas sub_parser_add_grid - sub_parser.on_head('--fmt STR', String, 'xy : header is like x, y...', 'yx : header is like y, x...') do |v| - options[:fmt] = v - end + sub_parser_add_fmt_yx sub_parser_add_ylim sub_parser_add_xlim when :lineplots, :lines sub_parser_add_canvas sub_parser_add_grid - sub_parser.on_head('--fmt STR', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...', - 'xyy : header is like x, y1, y2, y2, y3...') do |v| - options[:fmt] = v - end + sub_parser_add_fmt_xyxy sub_parser_add_ylim sub_parser_add_xlim when :scatter, :s sub_parser_add_canvas sub_parser_add_grid - sub_parser.on_head('--fmt STR', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...', - 'xyy : header is like x, y1, y2, y2, y3...') do |v| - options[:fmt] = v - end + sub_parser_add_fmt_xyxy sub_parser_add_ylim sub_parser_add_xlim when :density, :d sub_parser_add_canvas sub_parser_add_grid - sub_parser.on('--fmt STR', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...', - 'xyy : header is like x, y1, y2, y2, y3...') do |v| - options[:fmt] = v - end + sub_parser_add_fmt_xyxy sub_parser_add_ylim sub_parser_add_xlim