Class: Urban::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



10
11
12
# File 'lib/urban/cli.rb', line 10

def initialize
  @dictionary = Urban::Dictionary.new
end

Instance Attribute Details

#dictionaryObject

Returns the value of attribute dictionary.



8
9
10
# File 'lib/urban/cli.rb', line 8

def dictionary
  @dictionary
end

Instance Method Details

#run(args = ARGV) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/urban/cli.rb', line 14

def run(args = ARGV)

  options = parse(args)
  results = lookup(options)

  case
  when results.definitions
    generate_output results, options
  when results.phrase
    error "no definitions found for #{results.phrase.upcase}."
  else
    $stdout.puts options.version ? version : usage
  end

rescue SocketError
  error "no internet connection available."
rescue OptionParser::InvalidOption => e
  error "#{e.message}\nTry `urban --help' for more information."
rescue Object => e
  error e.message
end