Class: Wq::CLI::Commands::Random

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

Instance Method Summary collapse

Instance Method Details

#grouped_meaningsObject



37
38
39
# File 'lib/wq/cli/commands/random.rb', line 37

def grouped_meanings
  word[:meanings].group_by { |w| w[:partOfSpeech] }
end

#runObject



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

def run
  puts ""
  puts colors.yellow(colors.bold(word[:word]))
  puts ""

  grouped_meanings.each do |part_of_speech, meanings|
    puts part_of_speech
    puts ""
    indent(2) do
      meanings.each do |meaning|
        puts colors.white(meaning[:definition])
        puts ['"', meaning[:example], '"'].join

        synonyms = meaning[:synonyms].compact.join(", ")
        puts ["\u{21BB}", synonyms].join(" ") if !meaning[:synonyms].empty?

        puts ""
      end
    end
  end
end

#wordObject



33
34
35
# File 'lib/wq/cli/commands/random.rb', line 33

def word
  @word ||= Wq::Data.words.sample
end