Class: Wdim::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.


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

def initialize
  @commands = YAML.load_file(DICTIONARY_PATH)
  @decoratable = false
end

Instance Attribute Details

#decoratableObject

Returns the value of attribute decoratable


7
8
9
# File 'lib/wdim/cli.rb', line 7

def decoratable
  @decoratable
end

Instance Method Details

#decorate(meaning) ⇒ Object


37
38
39
# File 'lib/wdim/cli.rb', line 37

def decorate(meaning)
  "----------------------------------------\n\t#{meaning}\t\n----------------------------------------"
end

29
30
31
# File 'lib/wdim/cli.rb', line 29

def print_meaning(term)
  puts @decoratable ? decorate(search(term)) : search(term)
end

#replObject


20
21
22
23
24
25
26
27
# File 'lib/wdim/cli.rb', line 20

def repl
  @decoratable = true
  loop do
    print "> "
    typed_string = gets.chomp
    typed_string =~ /(exit|quit)/ ? break : print_meaning(typed_string)
  end
end

#search(term) ⇒ Object


33
34
35
# File 'lib/wdim/cli.rb', line 33

def search(term)
  @commands[term] || "Not registered in dictionary."
end

#start(argv) ⇒ Object


14
15
16
17
18
# File 'lib/wdim/cli.rb', line 14

def start(argv)
  # TODO: parse args and use as options
  return repl if argv.empty?
  print_meaning(argv[0])
end