Class: Wq::CLI::Commands::Today

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

Instance Method Summary collapse

Instance Method Details

#grouped_meaningsObject



44
45
46
# File 'lib/wq/cli/commands/today.rb', line 44

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

#quoteObject



48
49
50
# File 'lib/wq/cli/commands/today.rb', line 48

def quote
  @quote ||= Wq::Data.quotes.sample(random: random_today)
end

#random_todayObject



36
37
38
# File 'lib/wq/cli/commands/today.rb', line 36

def random_today
  @random_today ||= ::Random.new(Date.today.to_s.delete("-").to_i)
end

#runObject



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

def run
  puts "📚 Word of the Day"
  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 colors.gray(['"', meaning[:example], '"'].join)
        puts ""
      end
    end
  end
  puts ""
  puts "💬 Quote of the Day"
  puts ""
  indent(2) do
    puts "\"#{quote[:text]}\""
    puts colors.gray("-— #{quote[:author]}")
  end
end

#wordObject



40
41
42
# File 'lib/wq/cli/commands/today.rb', line 40

def word
  @word ||= Wq::Data.words.sample(random: random_today)
end