Class: Opener::PolarityTagger::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/opener/polarity_tagger/cli.rb

Overview

CLI wrapper around LanguageIdentifier using OptionParser.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • options (Hash) (defaults to: {})


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/opener/polarity_tagger/cli.rb', line 19

def initialize(options = {})
  @options = options

  @resource_switcher = Opener::Core::ResourceSwitcher.new
  component_options, options[:args] = Opener::Core::ArgvSplitter.split(options[:args])

  @option_parser = OptionParser.new do |opts|
    opts.program_name   = 'polarity-tagger'
    opts.summary_indent = '  '

    resource_switcher.bind(opts, @options)

    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', '--log', 'Enable logging to STDERR') do
      @options[:logging] = true
    end
  end

  option_parser.parse!(component_options)
  force = false
  resource_switcher.install(@options, force)
end

Instance Attribute Details

#option_parserOptionParser (readonly)

Returns:

  • (OptionParser)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/opener/polarity_tagger/cli.rb', line 13

class CLI
  attr_reader :options, :option_parser, :resource_switcher

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

    @resource_switcher = Opener::Core::ResourceSwitcher.new
    component_options, options[:args] = Opener::Core::ArgvSplitter.split(options[:args])

    @option_parser = OptionParser.new do |opts|
      opts.program_name   = 'polarity-tagger'
      opts.summary_indent = '  '

      resource_switcher.bind(opts, @options)

      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', '--log', 'Enable logging to STDERR') do
        @options[:logging] = true
      end
    end

    option_parser.parse!(component_options)
    force = false
    resource_switcher.install(@options, force)
  end

  ##
  # @param [String] input
  #
  def run(input)
    tagger = PolarityTagger.new(options)

    stdout, stderr, process = tagger.run(input)

    puts stdout
  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

#optionsHash (readonly)

Returns:

  • (Hash)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/opener/polarity_tagger/cli.rb', line 13

class CLI
  attr_reader :options, :option_parser, :resource_switcher

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

    @resource_switcher = Opener::Core::ResourceSwitcher.new
    component_options, options[:args] = Opener::Core::ArgvSplitter.split(options[:args])

    @option_parser = OptionParser.new do |opts|
      opts.program_name   = 'polarity-tagger'
      opts.summary_indent = '  '

      resource_switcher.bind(opts, @options)

      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', '--log', 'Enable logging to STDERR') do
        @options[:logging] = true
      end
    end

    option_parser.parse!(component_options)
    force = false
    resource_switcher.install(@options, force)
  end

  ##
  # @param [String] input
  #
  def run(input)
    tagger = PolarityTagger.new(options)

    stdout, stderr, process = tagger.run(input)

    puts stdout
  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

#resource_switcherObject (readonly)

Returns the value of attribute resource_switcher.



14
15
16
# File 'lib/opener/polarity_tagger/cli.rb', line 14

def resource_switcher
  @resource_switcher
end

Instance Method Details

#run(input) ⇒ Object

Parameters:

  • input (String)


52
53
54
55
56
57
58
# File 'lib/opener/polarity_tagger/cli.rb', line 52

def run(input)
  tagger = PolarityTagger.new(options)

  stdout, stderr, process = tagger.run(input)

  puts stdout
end