class KnittingPatterns::CLI

Public Instance Methods

call() click to toggle source
# File lib/knitting_patterns/cli.rb, line 3
def call
  puts "Hey fellow knitter!"
  puts "Here are the categories of the free knitting patterns from Purl Soho:"
  puts "___________________________________________________________________________________________"
  list_categories
  menu
end
choosing_a_pattern() click to toggle source
# File lib/knitting_patterns/cli.rb, line 56
def choosing_a_pattern
  puts ""
  puts "For more information on a specific pattern, please enter the corresponding number."
  puts "Or if none of these patterns are jumping out at you, type 'list' to see the categories again."
  puts "___________________________________________________________________________________________"
  input = nil
  while input != "exit"
    input = gets.strip.downcase

    if input.to_i > 0 && input.to_i <= KnittingPatterns::Pattern.all.size
      pattern = KnittingPatterns::Pattern.all[input.to_i-1]
      puts "___________________________________________________________________________________________"
      puts "#{pattern.title}"
      puts "___________________________________________________________________________________________"
      KnittingPatterns::Scraper.new.scrape_selected_pattern("#{pattern.url}")
      puts "___________________________________________________________________________________________"
      puts "To visit the website directly click here ----> #{pattern.url}"
      puts ""
      puts "If you would like to see another pattern in this category, simply enter the corresponding number."
      puts "If you would like to see the list of categories instead, type 'list'"
      puts "___________________________________________________________________________________________"
    elsif input == "list"
      call
    elsif input == "exit"
      goodbye
    else
      puts "Hmm, I don't see that pattern. Let's try this again."
      call
    end
  end
end
goodbye() click to toggle source
# File lib/knitting_patterns/cli.rb, line 88
def goodbye
  puts "Thanks for stopping by! Come back anytime to review more knitting patterns!"
  puts "___________________________________________________________________________________________"
  exit
end
list_categories() click to toggle source
# File lib/knitting_patterns/cli.rb, line 11
def list_categories
  puts ""
  @categories = KnittingPatterns::Scraper.new.scrape_knit_categories
  @categories.each.with_index(1) {|category, index| puts "#{index}. #{category}"}
  puts "___________________________________________________________________________________________"
end
list_category_patterns() click to toggle source
# File lib/knitting_patterns/cli.rb, line 18
def list_category_patterns
  puts "___________________________________________________________________________________________"
  puts ""
  KnittingPatterns::Scraper.new.scrape_category_patterns(@input)
  KnittingPatterns::Pattern.all.each_with_index do |pattern, index|
    puts "#{index+1}. #{pattern.title}"
  end
  puts "___________________________________________________________________________________________"
end
menu() click to toggle source