Class: Wdim::CLI
- Inherits:
-
Object
- Object
- Wdim::CLI
- Defined in:
- lib/wdim/cli.rb
Instance Attribute Summary collapse
-
#decoratable ⇒ Object
Returns the value of attribute decoratable.
Instance Method Summary collapse
- #decorate(meaning) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #print_meaning(term) ⇒ Object
- #repl ⇒ Object
- #search(term) ⇒ Object
- #start(argv) ⇒ Object
Constructor Details
#initialize ⇒ CLI
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
#decoratable ⇒ Object
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 |
#print_meaning(term) ⇒ Object
29 30 31 |
# File 'lib/wdim/cli.rb', line 29 def print_meaning(term) puts @decoratable ? decorate(search(term)) : search(term) end |
#repl ⇒ Object
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 |