Class: RandomWordByLength::CLI

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

Instance Method Summary collapse

Instance Method Details

#again?Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
68
# File 'lib/random_word_by_length/cli.rb', line 60

def again?
  puts "Would you like another random word? (y/n)"
  input = gets.strip.downcase
  if input == "y"
    level
  else
    exit!
  end
end

#callObject



3
4
5
6
# File 'lib/random_word_by_length/cli.rb', line 3

def call
  puts 'Welcome to Random Word By Length!'
level
end

#details?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/random_word_by_length/cli.rb', line 46

def details?
  puts "Would you like the definition and other details? (y/n)"
  input = gets.strip.downcase
  if input == "y"
    puts "The word #{@word.spelling.capitalize()} is of type: #{@word.kind}, and is #{@word.spelling.length} letters long."
    puts ""
    puts "The definition/s of #{@word.spelling}: #{@word.definition}."
    puts ""
    puts "Synonyms for #{@word.spelling.capitalize()} may be found here: #{@word.synonyms}."
    puts ""
  end
  again?
end

#easyObject



28
29
30
31
32
# File 'lib/random_word_by_length/cli.rb', line 28

def easy
  @word = RandomWordByLength::Word.easy
  puts "Your easy word is #{@word.spelling.capitalize()}."
  details?
end

#hardObject



40
41
42
43
44
# File 'lib/random_word_by_length/cli.rb', line 40

def hard
  @word = RandomWordByLength::Word.hard
  puts "Your hard word is #{@word.spelling.capitalize()}."
  details?
end

#levelObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/random_word_by_length/cli.rb', line 8

def level
  puts 'What difficulty level of word would you like?:'
  puts 'Type "e" (easy), "m" (medium) or "h" (hard)'
  puts 'To exit type "q"'
  input = gets.strip.downcase
  case input
  when "e"
    easy
  when "m"
    medium
  when "h"
    hard
  when "q"
    exit!
  else
    puts 'I do not understand your entry!'
    level
  end
end

#mediumObject



34
35
36
37
38
# File 'lib/random_word_by_length/cli.rb', line 34

def medium
  @word = RandomWordByLength::Word.medium
  puts "Your medium word is #{@word.spelling.capitalize()}."
  details?
end