Class: BeerMe::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/beer_me/cli.rb', line 6

def call
  doc = Nokogiri::HTML(open("https://www.ratebeer.com/Ratings/TopOfTheMonth.asp"))
  month_title = doc.css("h1").text
  puts ""
  puts "*****************************************"
  puts "******** " + month_title + "*********"
  puts "*****************************************"
  puts ""
  BeerMe::Beer.scrape_beers_site
  list_beers
  menu
  goodbye
end

#goodbyeObject



53
54
55
# File 'lib/beer_me/cli.rb', line 53

def goodbye
  puts "See you next month for the new best beers!"
end

#list_beersObject



20
21
22
23
24
# File 'lib/beer_me/cli.rb', line 20

def list_beers
  BeerMe::Beer.all.each.with_index(1) do |beer,i|
    puts "#{i}. #{beer.name}"
  end
end


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/beer_me/cli.rb', line 27

def menu
  input = nil
  while input != 'exit'
    puts ""
    puts "Enter beer number to display Beer Info or type 'list' to see the list again or type 'exit':"
    input = gets.strip.downcase
  
    if input.to_i.between?(1, BeerMe::Beer.all.length)
      #grabs the row based on input number and pulls the info for style, score and review number using nokogiri.
      beer = BeerMe::Beer.all[input.to_i - 1]

      puts "Beer Style: #{beer.style}"
      puts "Beer Score: #{beer.score}"
      puts "Beer Reviews: #{beer.reviews}"

    elsif input == "list"
      list_beers

    elsif input == "exit"

    elsif 
      puts "Please choose a valid number."   
    end
  end
end