Class: Opener::Scorer::CLI

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

Overview

CLI wrapper around Opener::Scorer using Slop.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



12
13
14
# File 'lib/opener/scorer/cli.rb', line 12

def initialize
  @parser = configure_slop
end

Instance Attribute Details

#parserSlop (readonly)

Returns:

  • (Slop)


9
10
11
12
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
# File 'lib/opener/scorer/cli.rb', line 9

class CLI
  attr_reader :parser

  def initialize
    @parser = configure_slop
  end

  ##
  # @param [Array] argv
  #
  def run(argv = ARGV)
    parser.parse(argv)
  end

  ##
  # @return [Slop]
  #
  def configure_slop
    return Slop.new(:strict => false, :indent => 2, :help => true) do
      banner 'Usage: scorer [OPTIONS]'

      separator <<-EOF.chomp

About:

Calculates and stores a score in MySQL based on an input KAF document.
This command reads input from STDIN.

Example:

cat some_file.kaf | scorer
      EOF

      separator "\nOptions:\n"

      on :v, :version, 'Shows the current version' do
        abort "scorer v#{VERSION} on #{RUBY_DESCRIPTION}"
      end

      run do |opts, args|
        scorer = OutputProcessor.new
        input  = STDIN.tty? ? nil : STDIN.read
        output = scorer.process(input)

        puts JSON.dump(output)
      end
    end
  end
end

Instance Method Details

#configure_slopSlop

Returns:

  • (Slop)


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
# File 'lib/opener/scorer/cli.rb', line 26

def configure_slop
  return Slop.new(:strict => false, :indent => 2, :help => true) do
    banner 'Usage: scorer [OPTIONS]'

    separator <<-EOF.chomp

About:

    Calculates and stores a score in MySQL based on an input KAF document.
    This command reads input from STDIN.

Example:

    cat some_file.kaf | scorer
    EOF

    separator "\nOptions:\n"

    on :v, :version, 'Shows the current version' do
      abort "scorer v#{VERSION} on #{RUBY_DESCRIPTION}"
    end

    run do |opts, args|
      scorer = OutputProcessor.new
      input  = STDIN.tty? ? nil : STDIN.read
      output = scorer.process(input)

      puts JSON.dump(output)
    end
  end
end

#run(argv = ARGV) ⇒ Object

Parameters:

  • argv (Array) (defaults to: ARGV)


19
20
21
# File 'lib/opener/scorer/cli.rb', line 19

def run(argv = ARGV)
  parser.parse(argv)
end