love_of_tea 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fd5e9e6338b9dd09562b66afe152ce9e28619537929b7770bfc29bbdc8da3e68
4
+ data.tar.gz: 026ae6e2a8910f473ec74c4fcc7d36a1a61b9c42bb87fe87c556eebcc97bf890
5
+ SHA512:
6
+ metadata.gz: 657582f2b55d63d9ca82ee482a2ef711512e58b42bc4b40ec7bf3aed4184e18f10db545c8b036ed11cb200caec3842fba94820a92a3f7b4fee528795290e8035
7
+ data.tar.gz: 4ad5ae695a91a83ef64094ecadd7c46f333def37891b7b720ab090d1f097d8efe4f356d9ceb986a26d70ebd731527755f937c5bfc05a5e69f92d74ceb8513427
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require_relative '../config/environment'
5
+
6
+ LoveOfTea::CLI.new.call
@@ -0,0 +1,18 @@
1
+
2
+ require 'require_all'
3
+ require 'pry'
4
+ require 'nokogiri'
5
+ require 'open-uri'
6
+
7
+ # require_all 'lib'
8
+
9
+ require_relative '../lib/love_of_tea/version'
10
+ require_relative '../lib/love_of_tea/scraper'
11
+ require_relative '../lib/love_of_tea/tea'
12
+ require_relative '../lib/love_of_tea/cli'
13
+
14
+
15
+ #
16
+ # module LoveOfTea
17
+ #
18
+ # end
@@ -0,0 +1,386 @@
1
+ require_relative '../../config/environment.rb'
2
+ require_relative './scraper.rb'
3
+ require_relative './tea.rb'
4
+
5
+ class LoveOfTea::CLI
6
+
7
+ def initialize
8
+ LoveOfTea::Tea.create_from_collection("https://www.rishi-tea.com/category/green-tea")
9
+ LoveOfTea::Tea.create_from_collection("https://www.rishi-tea.com/category/caffeine-free-herbal")
10
+ LoveOfTea::Tea.create_from_collection("https://www.rishi-tea.com/category/white-tea")
11
+ LoveOfTea::Tea.create_from_collection("https://www.rishi-tea.com/category/black-tea")
12
+ LoveOfTea::Tea.create_from_collection("https://www.rishi-tea.com/category/chai")
13
+ end
14
+
15
+ def call
16
+ menu
17
+ input = gets.strip
18
+ if input == "1"
19
+ learnmore
20
+ call
21
+ elsif input == "2"
22
+ quote
23
+ call
24
+ elsif input == "3"
25
+ match
26
+ call
27
+ elsif input == "4"
28
+ cart
29
+ elsif input != "exit"
30
+ invalid_input
31
+ call
32
+ else
33
+ end
34
+ end
35
+
36
+ def quote
37
+ 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"
38
+ end
39
+
40
+ def learnmore
41
+ 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"
42
+ end
43
+
44
+ def menu
45
+ 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"
46
+ end
47
+
48
+ def caffeine_prompt
49
+ puts "\nPlease choose a caffeine level.\n\n1. Low\n2. Medium\n3. High\n\n"
50
+ end
51
+
52
+ def selection_prompt
53
+ 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"
54
+ end
55
+
56
+ def invalid_input
57
+ puts "\nInvalid input. Please try again."
58
+ end
59
+
60
+ def match
61
+ puts "\nWhat sort of effect are you looking for in your tea?\n\n1. Energy\n2. Calming\n3. Warming/Spice\n\n"
62
+
63
+ effect = gets.strip
64
+
65
+ #Energy
66
+ if effect == "1"
67
+ caffeine_prompt
68
+
69
+ caffeine = gets.strip
70
+ if caffeine == "1"
71
+
72
+ selection_prompt
73
+ select_or_choose = gets.strip
74
+ if select_or_choose == "1"
75
+
76
+ randomtea = LoveOfTea::Tea.white.shuffle.first
77
+ name = randomtea.name
78
+ price = randomtea.price
79
+ description = randomtea.description
80
+ url = randomtea.url
81
+
82
+ 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"
83
+
84
+ savetocart = gets.strip
85
+ if savetocart == "y"
86
+ randomtea.save
87
+ else
88
+ end
89
+
90
+ elsif select_or_choose == "2"
91
+ list_white_tea
92
+ choose_from_list = gets.strip.to_i
93
+
94
+ if choose_from_list > LoveOfTea::Tea.white.length
95
+ invalid_input
96
+ list_white_tea
97
+ choose_from_list = gets.strip.to_i
98
+ else
99
+ end
100
+
101
+ tea = LoveOfTea::Tea.white[choose_from_list - 1]
102
+ name = tea.name
103
+ price = tea.price
104
+ description = tea.description
105
+ url = tea.url
106
+
107
+ 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"
108
+
109
+ savetocart = gets.strip
110
+ if savetocart == "y"
111
+ tea.save
112
+ else
113
+ end
114
+
115
+ else
116
+ invalid_input
117
+ match
118
+ end
119
+
120
+ elsif caffeine == "2"
121
+
122
+ selection_prompt
123
+ select_or_choose = gets.strip
124
+ if select_or_choose == "1"
125
+
126
+ randomtea = LoveOfTea::Tea.green.shuffle.first
127
+ name = randomtea.name
128
+ price = randomtea.price
129
+ description = randomtea.description
130
+ url = randomtea.url
131
+
132
+ 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"
133
+
134
+ savetocart = gets.strip
135
+ if savetocart == "y"
136
+ randomtea.save
137
+ else
138
+ end
139
+
140
+ elsif select_or_choose == "2"
141
+ list_green_tea
142
+ choose_from_list = gets.strip.to_i
143
+
144
+ if choose_from_list > LoveOfTea::Tea.green.length
145
+ invalid_input
146
+ list_green_tea
147
+ choose_from_list = gets.strip.to_i
148
+ else
149
+ end
150
+
151
+ tea = LoveOfTea::Tea.green[choose_from_list - 1]
152
+ name = tea.name
153
+ price = tea.price
154
+ description = tea.description
155
+ url = tea.url
156
+
157
+ 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"
158
+
159
+ savetocart = gets.strip
160
+ if savetocart == "y"
161
+ tea.save
162
+ else
163
+ end
164
+
165
+ else
166
+ invalid_input
167
+ match
168
+ end
169
+
170
+ elsif caffeine == "3"
171
+
172
+ selection_prompt
173
+ select_or_choose = gets.strip
174
+ if select_or_choose == "1"
175
+
176
+ randomtea = LoveOfTea::Tea.black.shuffle.first
177
+ name = randomtea.name
178
+ price = randomtea.price
179
+ description = randomtea.description
180
+ url = randomtea.url
181
+
182
+ 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"
183
+
184
+ savetocart = gets.strip
185
+ if savetocart == "y"
186
+ randomtea.save
187
+ else
188
+ invalid_input
189
+ match
190
+ end
191
+
192
+ elsif select_or_choose == "2"
193
+
194
+ list_black_tea
195
+ choose_from_list = gets.strip.to_i
196
+
197
+ if choose_from_list > LoveOfTea::Tea.black.length
198
+ invalid_input
199
+ list_black_tea
200
+ choose_from_list = gets.strip.to_i
201
+ else
202
+ end
203
+
204
+ tea = LoveOfTea::Tea.black[choose_from_list - 1]
205
+ name = tea.name
206
+ price = tea.price
207
+ description = tea.description
208
+ url = tea.url
209
+
210
+ 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"
211
+
212
+ savetocart = gets.strip
213
+ if savetocart == "y"
214
+ tea.save
215
+ else
216
+ end
217
+
218
+ else
219
+ invalid_input
220
+ match
221
+ end
222
+
223
+ else
224
+ invalid_input
225
+ match
226
+ end
227
+
228
+
229
+ #Calming
230
+ elsif effect == "2"
231
+
232
+ selection_prompt
233
+ select_or_choose = gets.strip
234
+ if select_or_choose == "1"
235
+
236
+ randomtea = LoveOfTea::Tea.herbal.shuffle.first
237
+ name = randomtea.name
238
+ price = randomtea.price
239
+ description = randomtea.description
240
+ url = randomtea.url
241
+
242
+ 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"
243
+
244
+ savetocart = gets.strip
245
+ if savetocart == "y"
246
+ randomtea.save
247
+ else
248
+ end
249
+
250
+ elsif select_or_choose == "2"
251
+ list_herbal_tea
252
+ choose_from_list = gets.strip.to_i
253
+
254
+ if choose_from_list > LoveOfTea::Tea.herbal.length
255
+ invalid_input
256
+ list_herbal_tea
257
+ choose_from_list = gets.strip.to_i
258
+ else
259
+ end
260
+
261
+ tea = LoveOfTea::Tea.herbal[choose_from_list - 1]
262
+ name = tea.name
263
+ price = tea.price
264
+ description = tea.description
265
+ url = tea.url
266
+
267
+ 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"
268
+
269
+ savetocart = gets.strip
270
+ if savetocart == "y"
271
+ tea.save
272
+ else
273
+ end
274
+
275
+ else
276
+ invalid_input
277
+ match
278
+ end
279
+
280
+ #Warming/Spice
281
+ elsif effect == "3"
282
+
283
+ selection_prompt
284
+ select_or_choose = gets.strip
285
+ if select_or_choose == "1"
286
+
287
+ randomtea = LoveOfTea::Tea.chai.shuffle.first
288
+ name = randomtea.name
289
+ price = randomtea.price
290
+ description = randomtea.description
291
+ url = randomtea.url
292
+
293
+ 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"
294
+
295
+ savetocart = gets.strip
296
+ if savetocart == "y"
297
+ randomtea.save
298
+ else
299
+ end
300
+
301
+ elsif select_or_choose == "2"
302
+
303
+ list_chai_tea
304
+ choose_from_list = gets.strip.to_i
305
+
306
+ if choose_from_list > LoveOfTea::Tea.chai.length
307
+ invalid_input
308
+ list_chai_tea
309
+ choose_from_list = gets.strip.to_i
310
+ else
311
+ end
312
+
313
+ tea = LoveOfTea::Tea.chai[choose_from_list - 1]
314
+ name = tea.name
315
+ price = tea.price
316
+ description = tea.description
317
+ url = tea.url
318
+
319
+ 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"
320
+
321
+ savetocart = gets.strip
322
+ if savetocart == "y"
323
+ tea.save
324
+ else
325
+ end
326
+
327
+ else
328
+ invalid_input
329
+ match
330
+ end
331
+
332
+ elsif effect != "exit"
333
+ invalid_input
334
+ match
335
+ else
336
+ end
337
+ end
338
+
339
+
340
+
341
+ def list_white_tea
342
+ puts "\n"
343
+ LoveOfTea::Tea.white.each_with_index do |tea, index| puts "#{index + 1}. #{tea.name}"
344
+ end
345
+ puts "\n"
346
+ end
347
+
348
+ def list_green_tea
349
+ puts "\n"
350
+ LoveOfTea::Tea.green.each_with_index do |tea, index| puts "#{index + 1}. #{tea.name}"
351
+ end
352
+ puts "\n"
353
+ end
354
+
355
+ def list_black_tea
356
+ puts "\n"
357
+ LoveOfTea::Tea.black.each_with_index do |tea, index| puts "#{index + 1}. #{tea.name}"
358
+ end
359
+ puts "\n"
360
+ end
361
+
362
+ def list_herbal_tea
363
+ puts "\n"
364
+ LoveOfTea::Tea.herbal.each_with_index do |tea, index| puts "#{index + 1}. #{tea.name}"
365
+ end
366
+ puts "\n"
367
+ end
368
+
369
+ def list_chai_tea
370
+ puts "\n"
371
+ LoveOfTea::Tea.chai.each_with_index do |tea, index| puts "#{index + 1}. #{tea.name}"
372
+ end
373
+ puts "\n"
374
+ end
375
+
376
+ def cart
377
+ puts "\n"
378
+ 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"
379
+ LoveOfTea::Tea.cart.each do |tea|
380
+ puts "Name: #{tea.name}\nType: #{tea.type}\nDescription: #{tea.description}\nPrice: #{tea.price}\nCaffeine Level: #{tea.caffeine}\nLink: #{tea.url}\n\n---------------------------"
381
+ end
382
+ puts "\n"
383
+ call
384
+ end
385
+
386
+ end
@@ -0,0 +1,35 @@
1
+ require_relative '../../config/environment.rb'
2
+ require_relative './tea.rb'
3
+ require_relative './cli.rb'
4
+
5
+ class LoveOfTea::Scraper
6
+
7
+
8
+ def self.scrape_by_tea_url(tea_url)
9
+ doc = Nokogiri::HTML(open(tea_url))
10
+ teas = []
11
+
12
+ doc.css(".product.clearfix").each do |tea|
13
+
14
+ price = tea.css("div.col-xs-12.col-sm-6 div.price.text-center").text.strip.gsub(/\s+/,'')
15
+
16
+ price2 = tea.css("div.col-sm-6.mar_btm div.col-sm-12 .price").text.strip.gsub(/\s+/,'')
17
+
18
+ tea_hash = {:name => tea.css("h3").text,
19
+ :description => tea.css("div.short-desc").text,
20
+ :price => price,
21
+ :price2 => price2,
22
+ :type => doc.css("header h1").text,
23
+ :url => "https://www.rishi-tea.com" + tea.css("a").attribute("href").value}
24
+
25
+ teas << tea_hash
26
+
27
+ end
28
+
29
+ teas.each do |teahash|
30
+ teahash.delete_if {|key, value| value == nil || value == ""}
31
+ end
32
+ teas
33
+ end
34
+
35
+ end
@@ -0,0 +1,68 @@
1
+ require_relative '../../config/environment.rb'
2
+ require_relative './scraper.rb'
3
+ require_relative './cli.rb'
4
+
5
+ class LoveOfTea::Tea
6
+ attr_accessor :name, :type, :price, :description, :caffeine, :url
7
+
8
+ @@all = []
9
+ @@cart = []
10
+
11
+ def initialize(teahash)
12
+ @name = teahash[:name]
13
+ @type = teahash[:type]
14
+ @price = teahash[:price] ? teahash[:price] : teahash[:price2]
15
+ @description = teahash[:description]
16
+ @caffeine = if teahash[:type] == "Green" then "medium" elsif teahash[:type] == "White" then "low" elsif teahash[:type] == "Black" || teahash[:type] == "Chai" then "high" else nil end
17
+ @url = teahash[:url]
18
+ @@all << self
19
+ end
20
+
21
+ def self.all
22
+ @@all
23
+ end
24
+
25
+ def self.clear_all
26
+ @@all.clear
27
+ end
28
+
29
+ def self.create_from_collection(tea_url)
30
+ LoveOfTea::Scraper.scrape_by_tea_url(tea_url).each do |teahash|
31
+ self.new(teahash)
32
+ end
33
+ end
34
+
35
+ def self.green
36
+ @@all.reject {|tea| tea.type != "Green"}
37
+ end
38
+
39
+ def self.white
40
+ @@all.reject {|tea| tea.type != "White"}
41
+ end
42
+
43
+ def self.black
44
+ @@all.reject {|tea| tea.type != "Black"}
45
+ end
46
+
47
+ def self.herbal
48
+ @@all.reject {|tea| tea.type != "Herbal"}
49
+ end
50
+
51
+ def self.chai
52
+ @@all.reject {|tea| tea.type != "Chai"}
53
+ end
54
+
55
+ def self.price_by_name(teaname)
56
+ tea = @@all.detect {|tea| tea.name == teaname}
57
+ tea.price
58
+ end
59
+
60
+ def save
61
+ @@cart << self
62
+ end
63
+
64
+ def self.cart
65
+ @@cart
66
+ end
67
+
68
+ end
@@ -0,0 +1,3 @@
1
+ module LoveOfTea
2
+ VERSION = "0.1.16"
3
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: love_of_tea
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.16
5
+ platform: ruby
6
+ authors:
7
+ - R.M.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: require_all
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.5.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.11.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.11.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: 'This application pairs you with teas scraped from the Rishi Tea website
84
+ based on desired effect and caffeine level. It allows you to place teas in a cart
85
+ and reference details and URLs for each tea to purchase. '
86
+ email:
87
+ - amouraveline@gmail.com
88
+ executables:
89
+ - loveoftea
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - bin/loveoftea
94
+ - config/environment.rb
95
+ - lib/love_of_tea/cli.rb
96
+ - lib/love_of_tea/scraper.rb
97
+ - lib/love_of_tea/tea.rb
98
+ - lib/love_of_tea/version.rb
99
+ homepage: https://github.com/avelineamour/love_of_tea
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.7.3
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Scrapes data from Rishi Tea website and pairs you with tea
123
+ test_files: []