Class: Opener::LanguageIdentifier::CLI
- Inherits:
-
Object
- Object
- Opener::LanguageIdentifier::CLI
- Defined in:
- lib/opener/language_identifier/cli.rb
Overview
CLI wrapper around Opener::LanguageIdentifier using Slop.
Instance Attribute Summary collapse
- #parser ⇒ Slop readonly
Instance Method Summary collapse
- #configure_slop ⇒ Slop
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run(argv = ARGV) ⇒ Object
Constructor Details
#initialize ⇒ CLI
12 13 14 |
# File 'lib/opener/language_identifier/cli.rb', line 12 def initialize @parser = configure_slop end |
Instance Attribute Details
#parser ⇒ Slop (readonly)
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/opener/language_identifier/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 'Usage: language-identifier [OPTIONS]' separator "\nAbout:\n\nLanguage detection for various languages such as English and Dutch. This\ncommand reads input from STDIN. Output can be a language code as plain text,\na KAF document containing the input text and language code, or a list of\nprobabilities.\n\nExample:\n\ncat some_file.kaf | language-identifier\n EOF\n\n separator \"\\nOptions:\\n\"\n\n on :v, :version, 'Shows the current version' do\n abort \"language-identifier v\#{VERSION} on \#{RUBY_DESCRIPTION}\"\n end\n\n on :'no-kaf', 'Disables KAF output'\n on :p, :probs, 'Displays probabilities instead of a language code'\n\n run do |opts, args|\n enable_kaf = true\n enable_probs = false\n\n if opts[:'no-kaf']\n enable_kaf = false\n end\n\n if opts[:probs]\n enable_kf = false\n enable_probs = true\n end\n\n identifier = LanguageIdentifier.new(\n :args => args,\n :kaf => enable_kaf,\n :probs => enable_probs\n )\n\n input = STDIN.tty? ? nil : STDIN.read\n\n puts identifier.run(input)\n end\n end\n end\nend\n".chomp |
Instance Method Details
#configure_slop ⇒ 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/opener/language_identifier/cli.rb', line 26 def configure_slop return Slop.new(:strict => false, :indent => 2, :help => true) do 'Usage: language-identifier [OPTIONS]' separator "\nAbout:\n\n Language detection for various languages such as English and Dutch. This\n command reads input from STDIN. Output can be a language code as plain text,\n a KAF document containing the input text and language code, or a list of\n probabilities.\n\nExample:\n\n cat some_file.kaf | language-identifier\n EOF\n\n separator \"\\nOptions:\\n\"\n\n on :v, :version, 'Shows the current version' do\n abort \"language-identifier v\#{VERSION} on \#{RUBY_DESCRIPTION}\"\n end\n\n on :'no-kaf', 'Disables KAF output'\n on :p, :probs, 'Displays probabilities instead of a language code'\n\n run do |opts, args|\n enable_kaf = true\n enable_probs = false\n\n if opts[:'no-kaf']\n enable_kaf = false\n end\n\n if opts[:probs]\n enable_kf = false\n enable_probs = true\n end\n\n identifier = LanguageIdentifier.new(\n :args => args,\n :kaf => enable_kaf,\n :probs => enable_probs\n )\n\n input = STDIN.tty? ? nil : STDIN.read\n\n puts identifier.run(input)\n end\n end\nend\n".chomp |
#run(argv = ARGV) ⇒ Object
19 20 21 |
# File 'lib/opener/language_identifier/cli.rb', line 19 def run(argv = ARGV) parser.parse(argv) end |