Class: Knitpickr::Controller
- Inherits:
-
Object
- Object
- Knitpickr::Controller
- Defined in:
- lib/knitpickr/controller.rb
Class Method Summary collapse
- .browse_by_fiber ⇒ Object
- .browse_by_name ⇒ Object
- .browse_by_weight ⇒ Object
- .browse_sale ⇒ Object
- .greeting ⇒ Object
Class Method Details
.browse_by_fiber ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/knitpickr/controller.rb', line 70 def self.browse_by_fiber puts "Here is a list of all yarn fiber content options - to learn more, enter the number listed below:" Knitpickr::Scraper.all_fibers.each_with_index {|x, i| puts "#{i+1}. #{x}"} puts "Want to learn more? Enter a number from above. You can also enter 'list' to see the list again, or 'exit'." input = gets.chomp until input.to_i != 0 || input == "exit" || input == "list" puts "Sorry - I don't understand. Please enter '1', '2', '3', '4', or 'exit':" input = gets.chomp end if input == "exit" puts "Ok, see you later!" return nil elsif input == "list" self.browse_by_fiber elsif input.to_i > 0 && input.to_i <= Knitpickr::Scraper.all_fibers.count index = input.to_i - 1 selection = Knitpickr::Yarn.find_by_fiber(Knitpickr::Scraper.all_fibers[index]) Knitpickr::Yarn.show_details(selection) else puts "Hmm, I don't see that number on the list. Let's try this again..." self.browse_by_fiber end puts "Browse again? (Y/N)" input = gets.chomp.downcase case input when "y" self.greeting when "n" puts "Ok, see you later!" return nil end end |
.browse_by_name ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/knitpickr/controller.rb', line 109 def self.browse_by_name puts "Here is a list of all yarn names - to learn more, enter the number listed below:" Knitpickr::Scraper.all_names.each_with_index {|x, i| puts "#{i+1}. #{x}"} puts "Want to learn more? Enter a number from above. You can also enter 'list' to see the list again, or 'exit'." input = gets.chomp until input.to_i != 0 || input == "exit" || input == "list" puts "Sorry - I don't understand. Please enter '1', '2', '3', '4', or 'exit':" input = gets.chomp end if input == "exit" puts "Ok, see you later!" return nil elsif input == "list" self.browse_by_name elsif input.to_i > 0 && input.to_i <= Knitpickr::Scraper.all_names.count index = input.to_i - 1 selection = Knitpickr::Yarn.find_by_name(Knitpickr::Scraper.all_names[index]) Knitpickr::Yarn.show_details(selection) else puts "Hmm, I don't see that number on the list. Let's try this again..." self.browse_by_name end puts "Browse again? (Y/N)" input = gets.chomp.downcase case input when "y" self.greeting when "n" puts "Ok, see you later!" return nil end end |
.browse_by_weight ⇒ Object
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/knitpickr/controller.rb', line 29 def self.browse_by_weight puts "Here is a list of all yarn weight options - to learn more, enter the number listed below:" Knitpickr::Scraper.all_weights.each_with_index {|x, i| puts "#{i+1}. #{x}"} puts "Want to learn more? Enter a number from above. You can also enter 'list' to see the list again, or 'exit'." input = gets.chomp until input.to_i != 0 || input == "exit" || input == "list" puts "Sorry - I don't understand. Please enter '1', '2', '3', '4', or 'exit':" input = gets.chomp end if input == "exit" puts "Ok, see you later!" return nil elsif input == "list" self.browse_by_weight elsif input.to_i > 0 && input.to_i <= Knitpickr::Scraper.all_weights.count index = input.to_i - 1 selection = Knitpickr::Yarn.find_by_weight(Knitpickr::Scraper.all_weights[index]) Knitpickr::Yarn.show_details(selection) else puts "Hmm, I don't see that number on the list. Let's try this again..." self.browse_by_weight end puts "Browse again? (Y/N)" input = gets.chomp.downcase case input when "y" self.greeting when "n" puts "Ok, see you later!" return nil end end |
.browse_sale ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/knitpickr/controller.rb', line 148 def self.browse_sale puts "Here is a list of all yarn currently on sale - to learn more, enter the number listed below:" Knitpickr::Scraper.all_sale.each_with_index {|x, i| puts "#{i+1}. #{x.name} (#{x.price})"} puts "Want to learn more? Enter a number from above. You can also enter 'list' to see the list again, or 'exit'." input = gets.chomp until input.to_i != 0 || input == "exit" || input == "list" puts "Sorry - I don't understand. Please enter '1', '2', '3', '4', or 'exit':" input = gets.chomp end if input == "exit" puts "Ok, see you later!" return nil elsif input == "list" self.browse_sale elsif input.to_i > 0 && input.to_i <= Knitpickr::Scraper.all_sale.count index = input.to_i - 1 selection = Knitpickr::Scraper.all_sale[index] puts "Yarn name: #{selection.name}" puts "Yarn weight: #{selection.weight}" puts "Fiber content: #{selection.fiber}" puts "Price: #{selection.price}" if selection.sale puts "On sale!" end else puts "Hmm, I don't see that number on the list. Let's try this again..." self.browse_sale end puts "Browse again? (Y/N)" input = gets.chomp.downcase case input when "y" self.greeting when "n" puts "Ok, see you later!" return nil end end |
.greeting ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/knitpickr/controller.rb', line 3 def self.greeting puts "Hello! Would you like to browse by [1] yarn weight, [2] fiber content, [3] yarn name, or [4] all sale items? Please enter '1', '2', '3', or '4':" input = gets.chomp.to_s until input == "1" || input == "2" || input == "3" || input == "4" || input == "exit" puts "Sorry - I don't understand. Please enter '1', '2', '3', '4' or 'exit':" input = gets.chomp.to_s end case input when "1" browse_by_weight when "2" browse_by_fiber when "3" browse_by_name when "4" browse_sale when "exit" puts "Ok, see you later!" return nil end end |