Class: KnittingPatterns::CLI
- Inherits:
-
Object
- Object
- KnittingPatterns::CLI
- Defined in:
- lib/knitting_patterns/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #choosing_a_pattern ⇒ Object
- #goodbye ⇒ Object
- #list_categories ⇒ Object
- #list_category_patterns ⇒ Object
- #menu ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 9 |
# 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 end |
#choosing_a_pattern ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# 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 ⇒ Object
88 89 90 91 92 |
# 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 ⇒ Object
11 12 13 14 15 16 |
# 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 ⇒ Object
18 19 20 21 22 23 24 25 26 |
# 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 ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/knitting_patterns/cli.rb', line 28 def input = nil while input != "exit" puts "" puts "To see all the patterns in a category, enter the corresponding number." puts "Type 'list' to see them all again or 'exit' at anytime to leave." puts "___________________________________________________________________________________________" input = gets.strip.downcase if input.to_i == 7 @input = "toys-hobbies" list_category_patterns choosing_a_pattern elsif input.to_i > 0 && input.to_i <= @categories.size @input = @categories[input.to_i-1] list_category_patterns choosing_a_pattern elsif input == "list" puts "Interested in some more ideas, huh?" list_categories elsif input == "exit" goodbye else print "Hmm, I'm not seeing that category. " end end end |