Class: Classifier::Keywords::CLI
- Defined in:
- lib/classifier/keywords/cli.rb
Defined Under Namespace
Classes: UsageError
Instance Method Summary collapse
-
#initialize(args, stdin: nil) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(args, stdin: nil) ⇒ CLI
Returns a new instance of CLI.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/classifier/keywords/cli.rb', line 21 def initialize(args, stdin: nil) @args = args.dup @stdin = stdin @options = { model: File.('./keywords.json'), top: nil, quiet: false, min_df: 1, max_df: 1.0, ngram_range: [1, 1] } @output = [] @error = [] @exit_code = 0 end |
Instance Method Details
#run ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/classifier/keywords/cli.rb', line 37 def run execute_command { output: @output.join("\n"), error: @error.join("\n"), exit_code: @exit_code } rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::InvalidArgument, UsageError => e @error << "Error: #{e.}" @exit_code = 2 { output: @output.join("\n"), error: @error.join("\n"), exit_code: @exit_code } rescue StandardError => e @error << "Error: #{e.}" @exit_code = 1 { output: @output.join("\n"), error: @error.join("\n"), exit_code: @exit_code } end |