Class: LoveOfTea::CLI

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

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



7
8
9
10
11
12
13
# File 'lib/love_of_tea/cli.rb', line 7

def initialize
  LoveOfTea::Tea.create_from_collection("https://www.rishi-tea.com/category/green-tea")
  LoveOfTea::Tea.create_from_collection("https://www.rishi-tea.com/category/caffeine-free-herbal")
  LoveOfTea::Tea.create_from_collection("https://www.rishi-tea.com/category/white-tea")
  LoveOfTea::Tea.create_from_collection("https://www.rishi-tea.com/category/black-tea")
  LoveOfTea::Tea.create_from_collection("https://www.rishi-tea.com/category/chai")
end

Instance Method Details

#caffeine_promptObject



48
49
50
# File 'lib/love_of_tea/cli.rb', line 48

def caffeine_prompt
  puts "\nPlease choose a caffeine level.\n\n1. Low\n2. Medium\n3. High\n\n"
end

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/love_of_tea/cli.rb', line 15

def call
  menu
  input = gets.strip
  if input == "1"
    learnmore
    call
  elsif input == "2"
    quote
    call
  elsif input == "3"
    match
    call
  elsif input == "4"
    cart
  elsif input != "exit"
    invalid_input
    call
  else
  end
end

#cartObject



376
377
378
379
380
381
382
383
384
# File 'lib/love_of_tea/cli.rb', line 376

def cart
  puts "\n"
  puts "\nHere are the teas that you have saved to your cart. Please note that a blank caffeine level indicates no caffeine. To purchase and see more details, copy the URLs into your browser for your desired teas.\n\n"
  LoveOfTea::Tea.cart.each do |tea|
    puts "Name: #{tea.name}\nType: #{tea.type}\nDescription: #{tea.description}\nPrice: #{tea.price}\nCaffeine Level: #{tea.caffeine}\nLink: #{tea.url}\n\n---------------------------"
  end
  puts "\n"
  call
end

#invalid_inputObject



56
57
58
# File 'lib/love_of_tea/cli.rb', line 56

def invalid_input
  puts "\nInvalid input. Please try again."
end

#learnmoreObject



40
41
42
# File 'lib/love_of_tea/cli.rb', line 40

def learnmore
 puts "\n\n❀ All tea comes from the camellia sinensis plant. Otherwise, it is a tisane. The camellia plant has many health properties, but one of particular interest is its L-Theanine content. ❀\n\n\n❀ L-theanine has been shown to increase dopamine, serotonin, and GABA in the brain, thus inducing relaxation and positive mood. ❀\n\n\n❀ Combined with the natural caffeine in the plant, it also improves concentration and memory, which is why monks have used it to meditate for years. ❀\n\n"
end

#list_black_teaObject



355
356
357
358
359
360
# File 'lib/love_of_tea/cli.rb', line 355

def list_black_tea
  puts "\n"
  LoveOfTea::Tea.black.each_with_index do |tea, index| puts "#{index + 1}. #{tea.name}"
  end
  puts "\n"
end

#list_chai_teaObject



369
370
371
372
373
374
# File 'lib/love_of_tea/cli.rb', line 369

def list_chai_tea
  puts "\n"
  LoveOfTea::Tea.chai.each_with_index do |tea, index| puts "#{index + 1}. #{tea.name}"
  end
  puts "\n"
end

#list_green_teaObject



348
349
350
351
352
353
# File 'lib/love_of_tea/cli.rb', line 348

def list_green_tea
  puts "\n"
  LoveOfTea::Tea.green.each_with_index do |tea, index| puts "#{index + 1}. #{tea.name}"
  end
  puts "\n"
end

#list_herbal_teaObject



362
363
364
365
366
367
# File 'lib/love_of_tea/cli.rb', line 362

def list_herbal_tea
  puts "\n"
  LoveOfTea::Tea.herbal.each_with_index do |tea, index| puts "#{index + 1}. #{tea.name}"
  end
  puts "\n"
end

#list_white_teaObject



341
342
343
344
345
346
# File 'lib/love_of_tea/cli.rb', line 341

def list_white_tea
  puts "\n"
  LoveOfTea::Tea.white.each_with_index do |tea, index| puts "#{index + 1}. #{tea.name}"
  end
  puts "\n"
end

#matchObject



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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
147
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/love_of_tea/cli.rb', line 60

def match
  puts "\nWhat sort of effect are you looking for in your tea?\n\n1. Energy\n2. Calming\n3. Warming/Spice\n\n"

  effect = gets.strip

  #Energy
  if effect == "1"
    caffeine_prompt

    caffeine = gets.strip
    if caffeine == "1"

      selection_prompt
      select_or_choose = gets.strip
        if select_or_choose == "1"

          randomtea = LoveOfTea::Tea.white.shuffle.first
          name = randomtea.name
          price = randomtea.price
          description = randomtea.description
          url = randomtea.url

          puts "\nWe have chosen the lovely #{name} for you. #{description}. Depending on quantity, that will cost #{price}. If the price is fixed, that is the only quantity offered. Enjoy!\n\nWould you like to save this to your cart? (y/n)\n\n"

          savetocart = gets.strip
          if savetocart == "y"
            randomtea.save
          else
          end

        elsif select_or_choose == "2"
          list_white_tea
          choose_from_list = gets.strip.to_i

          if choose_from_list > LoveOfTea::Tea.white.length
            invalid_input
            list_white_tea
            choose_from_list = gets.strip.to_i
          else
          end

          tea = LoveOfTea::Tea.white[choose_from_list - 1]
          name = tea.name
          price = tea.price
          description = tea.description
          url = tea.url

            puts "\n#{name}. Excellent choice. #{description}. Depending on quantity that will cost #{price}. If the price is fixed, that is the only quantity offered.\n\nWould you like to save this to your cart? (y/n)\n\n"

            savetocart = gets.strip
            if savetocart == "y"
              tea.save
            else
            end

        else
          invalid_input
          match
        end

    elsif caffeine == "2"

      selection_prompt
      select_or_choose = gets.strip
        if select_or_choose == "1"

          randomtea = LoveOfTea::Tea.green.shuffle.first
          name = randomtea.name
          price = randomtea.price
          description = randomtea.description
          url = randomtea.url

          puts "\nWe have chosen the lovely #{name} for you. #{description}. Depending on quantity, that will cost #{price}. If the price is fixed, that is the only quantity offered. Enjoy!\n\nWould you like to save this to your cart? (y/n)\n\n"

          savetocart = gets.strip
          if savetocart == "y"
            randomtea.save
          else
          end

        elsif select_or_choose == "2"
          list_green_tea
          choose_from_list = gets.strip.to_i

          if choose_from_list > LoveOfTea::Tea.green.length
            invalid_input
            list_green_tea
            choose_from_list = gets.strip.to_i
          else
          end

          tea = LoveOfTea::Tea.green[choose_from_list - 1]
          name = tea.name
          price = tea.price
          description = tea.description
          url = tea.url

            puts "\n#{name}. Excellent choice. #{description}. Depending on quantity that will cost #{price}. If the price is fixed, that is the only quantity offered.\n\nWould you like to save this to your cart? (y/n)\n\n"

            savetocart = gets.strip
            if savetocart == "y"
              tea.save
            else
            end

        else
          invalid_input
          match
        end

    elsif caffeine == "3"

      selection_prompt
      select_or_choose = gets.strip
        if select_or_choose == "1"

          randomtea = LoveOfTea::Tea.black.shuffle.first
          name = randomtea.name
          price = randomtea.price
          description = randomtea.description
          url = randomtea.url

          puts "\nWe have chosen the lovely #{name} for you. #{description}. Depending on quantity, that will cost #{price}. If the price is fixed, that is the only quantity offered. Enjoy!\n\nWould you like to save this to your cart? (y/n)\n\n"

          savetocart = gets.strip
          if savetocart == "y"
            randomtea.save
          else
            invalid_input
            match
          end

        elsif select_or_choose == "2"

          list_black_tea
          choose_from_list = gets.strip.to_i

          if choose_from_list > LoveOfTea::Tea.black.length
            invalid_input
            list_black_tea
            choose_from_list = gets.strip.to_i
          else
          end

          tea = LoveOfTea::Tea.black[choose_from_list - 1]
          name = tea.name
          price = tea.price
          description = tea.description
          url = tea.url

          puts "\n#{name}. Excellent choice. #{description}. Depending on quantity that will cost #{price}. If the price is fixed, that is the only quantity offered.\n\nWould you like to save this to your cart? (y/n)\n\n"

          savetocart = gets.strip
            if savetocart == "y"
              tea.save
            else
            end

          else
            invalid_input
            match
          end

    else
      invalid_input
      match
    end


  #Calming
  elsif effect == "2"

    selection_prompt
    select_or_choose = gets.strip
      if select_or_choose == "1"

        randomtea = LoveOfTea::Tea.herbal.shuffle.first
        name = randomtea.name
        price = randomtea.price
        description = randomtea.description
        url = randomtea.url

        puts "\nWe have chosen the lovely #{name} for you. #{description}. Depending on quantity, that will cost #{price}. If the price is fixed, that is the only quantity offered. Enjoy!\n\nWould you like to save this to your cart? (y/n)\n\n"

        savetocart = gets.strip
        if savetocart == "y"
          randomtea.save
        else
        end

      elsif select_or_choose == "2"
        list_herbal_tea
        choose_from_list = gets.strip.to_i

        if choose_from_list > LoveOfTea::Tea.herbal.length
          invalid_input
          list_herbal_tea
          choose_from_list = gets.strip.to_i
        else
        end

        tea = LoveOfTea::Tea.herbal[choose_from_list - 1]
        name = tea.name
        price = tea.price
        description = tea.description
        url = tea.url

          puts "\n#{name}. Excellent choice. #{description}. Depending on quantity that will cost #{price}. If the price is fixed, that is the only quantity offered.\n\nWould you like to save this to your cart? (y/n)\n\n"

          savetocart = gets.strip
          if savetocart == "y"
            tea.save
          else
          end

      else
        invalid_input
        match
      end

  #Warming/Spice
  elsif effect == "3"

    selection_prompt
    select_or_choose = gets.strip
      if select_or_choose == "1"

        randomtea = LoveOfTea::Tea.chai.shuffle.first
        name = randomtea.name
        price = randomtea.price
        description = randomtea.description
        url = randomtea.url

        puts "\nWe have chosen the lovely #{name} for you. #{description}. Depending on quantity, that will cost #{price}. If the price is fixed, that is the only quantity offered. Enjoy!\n\nWould you like to save this to your cart? (y/n)\n\n"

        savetocart = gets.strip
        if savetocart == "y"
          randomtea.save
        else
        end

      elsif select_or_choose == "2"

        list_chai_tea
        choose_from_list = gets.strip.to_i

        if choose_from_list > LoveOfTea::Tea.chai.length
          invalid_input
          list_chai_tea
          choose_from_list = gets.strip.to_i
        else
        end

        tea = LoveOfTea::Tea.chai[choose_from_list - 1]
        name = tea.name
        price = tea.price
        description = tea.description
        url = tea.url

          puts "\n#{name}. Excellent choice. #{description}. Depending on quantity that will cost #{price}. If the price is fixed, that is the only quantity offered.\n\nWould you like to save this to your cart? (y/n)\n\n"

          savetocart = gets.strip
          if savetocart == "y"
            tea.save
          else
          end

      else
        invalid_input
        match
      end

  elsif effect != "exit"
    invalid_input
    match
  else
  end
end


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

def menu
  puts "\nHello and welcome to Love of Tea. This application will help you learn about tea and select the perfect teas for you. To begin, please select an option by typing the number. You may exit the program at any time by typing exit and use the Tea Matcher as many times as you wish to populate your cart.\n\n1. Learn More About Tea\n2. A Quote About Tea\n3. Get Matched with A Tea\n4. See Cart\n\n"
end

#quoteObject



36
37
38
# File 'lib/love_of_tea/cli.rb', line 36

def quote
 puts "\n\n❀ Why not consecrate ourselves to the queen of the Camelias, and revel in the warm stream of sympathy that flows from her altar?  In the liquid amber within the ivory-porcelain, the initiated may touch the sweet reticence of Confucius, the piquancy of Laotse, and the ethereal aroma of Sakyamuni himself. ❀\n\n"
end

#selection_promptObject



52
53
54
# File 'lib/love_of_tea/cli.rb', line 52

def selection_prompt
  puts "\nWould you like us to select a tea for you? Or would you prefer to choose from a list?\n\n1. Select For Me\n2. Choose My Own\n\n"
end