Class: Urban::CLI
- Inherits:
-
Object
- Object
- Urban::CLI
- Defined in:
- lib/urban/cli.rb
Instance Attribute Summary collapse
-
#dictionary ⇒ Object
Returns the value of attribute dictionary.
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run(args = ARGV) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
11 12 13 |
# File 'lib/urban/cli.rb', line 11 def initialize @dictionary = Urban::Dictionary end |
Instance Attribute Details
#dictionary ⇒ Object
Returns the value of attribute dictionary.
9 10 11 |
# File 'lib/urban/cli.rb', line 9 def dictionary @dictionary end |
Instance Method Details
#run(args = ARGV) ⇒ Object
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 |
# File 'lib/urban/cli.rb', line 15 def run(args = ARGV) begin = parse(args) output = case when .help ; .help_screen when .version ; "Urban #{Urban::VERSION} (c) Thomas Miller" when .random ; dictionary.random when !.phrase.empty? ; dictionary.search(.phrase) else ; .help_screen end if output.respond_to?(:phrase) if output.definitions print_entry(output, ) else $stderr.puts "urban: no definitions found for #{entry.phrase.upcase}." end else puts output end rescue SocketError $stderr.puts 'urban: no internet connection available.' rescue OptionParser::InvalidOption => e $stderr.puts "urban: #{e.}\nTry `urban --help' for more information." rescue Exception => e $stderr.puts e. end end |