Class: Wq::CLI::Commands::List

Inherits:
CommandKit::Command
  • Object
show all
Includes:
CommandKit::Colors, CommandKit::Printing::Indent
Defined in:
lib/wq/cli/commands/list.rb

Instance Method Summary collapse

Instance Method Details

#run(letter = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wq/cli/commands/list.rb', line 13

def run(letter=nil)
  if letter.nil?
    words = Wq::Data.words
  else
    words = Wq::Data.words.select { |w| w[:word].start_with?(letter.downcase) }
  end

  if words.empty?
    print_error("No words found starting with '#{letter.downcase}'.")
    exit 1
  else
    words.each do |word|
      puts "#{word[:word]} - #{word[:meanings].first[:definition]}"
    end
  end
end