Class: Horoscopes::CLI

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

Overview

CLI Controller

Instance Method Summary collapse

Instance Method Details

#callObject



4
5
6
7
8
9
# File 'lib/horoscopes/cli.rb', line 4

def call
  puts "Welcome to daily horoscopes!"
  Horoscopes::Scraper.new.signs
  list_zodiac
  main_menu
end

#goodbyeObject



44
45
46
# File 'lib/horoscopes/cli.rb', line 44

def goodbye
  puts "Come back later for tomorrow's horoscopes! <3"
end

#horoscope_readingObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/horoscopes/cli.rb', line 30

def horoscope_reading
  puts "Please type menu for list of zodiac signs or exit to leave:"
  answer = gets.strip.downcase
  case answer
  when "exit"
  goodbye
  when "menu"
    list_zodiac
    main_menu
  else
    horoscope_reading
  end
end

#list_zodiacObject



11
12
13
14
15
# File 'lib/horoscopes/cli.rb', line 11

def list_zodiac
  Horoscopes::Zodiacs.all.each.with_index(1) do |sign, index|
    puts "#{index}. #{sign.name}: #{sign.birthday}"
  end
end


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/horoscopes/cli.rb', line 17

def main_menu
  puts "Please enter the number of your zodiac sign from the list above:"
    input = gets.strip.to_i
    if input.between?(1, Horoscopes::Zodiacs.all.size)
      puts "Today's Reading:"
      puts Horoscopes::Scraper.new.reading[input - 1].reading
      horoscope_reading
    else
      puts "Looks like that doesn't exist in the stars..."
      main_menu
    end
end