From 21923459157bfacef51912fbf877f1785793da32 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Sat, 16 Mar 2024 15:42:22 -0400 Subject: [PATCH] Refactor code and add a json option --- bin/churn | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/bin/churn b/bin/churn index 49f2d12..092c370 100755 --- a/bin/churn +++ b/bin/churn @@ -7,6 +7,7 @@ bin_file = Pathname.new(__FILE__).realpath $:.unshift File.expand_path("../../lib", bin_file) require 'churn/calculator' +require 'churn/reporter' require 'churn/version' require 'main' require 'yaml' @@ -24,6 +25,11 @@ Main do default false end + option('json', 'j') do + cast :boolean + default false + end + option('ignore_files', 'i') do cast :string argument :optional @@ -80,33 +86,9 @@ Main do default false end - def report_churn(output_string) - options = { - minimum_churn_count: params['minimum_churn_count'].value, - ignore_files: params['ignore_files'].value, - start_date: params['start_date'].value, - data_directory: params['data_directory'].value, - history: params['past_history'].value, - report: params['report'].value, - name: params['name'].value, - file_extension: params['extension'].value, - file_prefix: params['prefix'].value, - } - if params['version'].value - puts Churn::VERSION - return - end - - result = Churn::ChurnCalculator.new(options).report(output_string) - if output_string - result - else - YAML::dump(result) - end - end - def run - report = report_churn(!params['yaml'].value) + reporter = Churn::ChurnReporter.new(params) + report = reporter.report_churn puts report end end