Sha256: f3467856cfddf1b6661b4675f58abb1149c67e5ef3005cbf5614e9a0153aa85c

Contents?: true

Size: 1.77 KB

Versions: 9

Compression:

Stored size: 1.77 KB

Contents

module Opener
  class Ner
    ##
    # CLI wrapper around {Opener::Ner} using OptionParser.
    #
    # @!attribute [r] options
    #  @return [Hash]
    # @!attribute [r] option_parser
    #  @return [OptionParser]
    #
    class CLI
      attr_reader :options, :option_parser

      ##
      # @param [Hash] options
      #
      def initialize(options = {})
        @options = DEFAULT_OPTIONS.merge(options)

        @option_parser = OptionParser.new do |opts|
          opts.program_name   = 'ner'
          opts.summary_indent = '  '

          opts.on('-h', '--help', 'Shows this help message') do
            show_help
          end

          opts.on('-v', '--version', 'Shows the current version') do
            show_version
          end

          opts.on(
            '-l',
            '--language [VALUE]',
            'Uses this specific language'
          ) do |value|
            @options[:language] = value
          end

          opts.separator <<-EOF

Examples:

  cat example.kaf | #{opts.program_name} -l en

Languages:

  Ner will try to detect the language of the KAF file if no language is given.

  * Dutch (nl)
  * English (en)
  * French (fr)
  * German (de)
  * Italian (it)
  * Spanish (es)
          EOF
        end
      end

      ##
      # @param [String] input
      #
      def run(input)
        option_parser.parse!(options[:args])

        ner = Ner.new(options)

        return ner.run(input)
      end

      private

      ##
      # Shows the help message and exits the program.
      #
      def show_help
        abort option_parser.to_s
      end

      ##
      # Shows the version and exits the program.
      #
      def show_version
        abort "#{option_parser.program_name} v#{VERSION} on #{RUBY_DESCRIPTION}"
      end
    end # CLI
  end # Ner
end # Opener

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
opener-ner-2.1.0 lib/opener/ner/cli.rb
opener-ner-2.0.7 lib/opener/ner/cli.rb
opener-ner-2.0.6 lib/opener/ner/cli.rb
opener-ner-2.0.5 lib/opener/ner/cli.rb
opener-ner-2.0.4 lib/opener/ner/cli.rb
opener-ner-2.0.3 lib/opener/ner/cli.rb
opener-ner-2.0.2 lib/opener/ner/cli.rb
opener-ner-2.0.1 lib/opener/ner/cli.rb
opener-ner-2.0.0 lib/opener/ner/cli.rb