Class: IndoorJungle::PlantAssistant

Inherits:
Object
  • Object
show all
Defined in:
lib/indoor_jungle/plant_assistant.rb

Overview

CLI Controller

Constant Summary collapse

BASE_PATH =
"https://www.plants.com/c/all-plants"
@@cold =

house the least amount of plants

[]
@@room_temp =

should house the most plants

[]
@@warm =

house most plants

[]
@@low_light =

should house least amount

[]
@@medium_light =

should house most

[]
@@high_light =

should house all except ones that cant take bright sun

[]
@@low_maintenance =

when soil is dry “drought tolerant”

[]
@@medium_maintenance =

water once a week “moderate”

[]
@@high_maintenance =

“keep humidity tray full” “saturated” “ambient humidity” “do not”

[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlantAssistant

Returns a new instance of PlantAssistant.



16
17
18
19
20
# File 'lib/indoor_jungle/plant_assistant.rb', line 16

def initialize
  make_plants
  add_attributes_to_plants
  sort_plants
end

Class Method Details

.coldObject



227
228
229
230
231
232
233
234
# File 'lib/indoor_jungle/plant_assistant.rb', line 227

def self.cold
  puts "-----------------------".green
  @@cold.each do |plant|
    puts plant.name
    puts plant.temperature
    puts "-----------------------".green
  end
end

.high_lightObject



272
273
274
275
276
277
278
279
# File 'lib/indoor_jungle/plant_assistant.rb', line 272

def self.high_light
  puts "-----------------------".green
  @@high_light.each do |plant|
    puts plant.name
    puts plant.sunlight[0]
    puts "-----------------------".green
  end
end

.high_maintenanceObject



299
300
301
302
303
304
305
306
# File 'lib/indoor_jungle/plant_assistant.rb', line 299

def self.high_maintenance
  puts "-----------------------".green
  @@high_maintenance.each do |plant|
    puts plant.name
    puts plant.water
    puts "-----------------------".green
  end
end

.low_lightObject



254
255
256
257
258
259
260
261
# File 'lib/indoor_jungle/plant_assistant.rb', line 254

def self.low_light
  puts "-----------------------".green
  @@low_light.each do |plant|
    puts plant.name
    puts plant.sunlight[0]
    puts "-----------------------".green
  end
end

.low_maintenanceObject



281
282
283
284
285
286
287
288
# File 'lib/indoor_jungle/plant_assistant.rb', line 281

def self.low_maintenance
  puts "-----------------------".green
  @@low_maintenance.each do |plant|
    puts plant.name
    puts plant.water
    puts "-----------------------".green
  end
end

.medium_lightObject



263
264
265
266
267
268
269
270
# File 'lib/indoor_jungle/plant_assistant.rb', line 263

def self.medium_light
  puts "-----------------------".green
  @@medium_light.each do |plant|
    puts plant.name
    puts plant.sunlight[0]
    puts "-----------------------".green
  end
end

.medium_maintenanceObject



290
291
292
293
294
295
296
297
# File 'lib/indoor_jungle/plant_assistant.rb', line 290

def self.medium_maintenance
  puts "-----------------------".green
  @@medium_maintenance.each do |plant|
    puts plant.name
    puts plant.water
    puts "-----------------------".green
  end
end

.room_tempObject



236
237
238
239
240
241
242
243
# File 'lib/indoor_jungle/plant_assistant.rb', line 236

def self.room_temp
  puts "-----------------------".green
  @@room_temp.each do |plant|
    puts plant.name
    puts plant.temperature
    puts "-----------------------".green
  end
end

.warmObject



245
246
247
248
249
250
251
252
# File 'lib/indoor_jungle/plant_assistant.rb', line 245

def self.warm
  puts "-----------------------".green
  @@warm.each do |plant|
    puts plant.name
    puts plant.temperature
    puts "-----------------------".green
  end
end

Instance Method Details

#add_attributes_to_plantsObject



27
28
29
30
31
32
# File 'lib/indoor_jungle/plant_assistant.rb', line 27

def add_attributes_to_plants
    IndoorJungle::Plant.all.each do |plant|
    attributes = IndoorJungle::Scraper.scrape_plant(plant.plant_url)
    plant.add_plant_attributes(attributes)
  end
end

#callObject



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
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
# File 'lib/indoor_jungle/plant_assistant.rb', line 34

def call
  #cold, low_light, low_maintenance
  switch = nil
  plants = []
  temp = nil
  light = nil
  attention = nil
  temp_input = nil
  light_input = nil
  attention_input = nil
  input_2 = nil


  puts "To get started, we need to get some more information about you"
  sleep(1)
  puts "Would you describe your home temperature to as: cool(around 60F), room temp(around 70F), or warm? (around or above 80F)"

  until temp_input == "cool" || temp_input == "cold" || temp_input == "colder" || temp_input == "room temp" || temp_input == "room" || temp_input == "average" || temp_input == "warm" || temp_input == "tropical" || temp_input == "hot"
    temp_input = gets.chomp
  end

  if temp_input == "cool" || temp_input == "cold" || temp_input == "colder"
    temp = @@cold
  elsif temp_input == "room temp" || temp_input == "room" || temp_input == "average"
    temp = @@room_temp
  elsif  temp_input == "warm" || temp_input == "hot" || temp_input == "tropical"
    temp = @@warm
  end

  puts "Would you describe the light sources in your home as: low light, medium light, or bright?"

  until light_input == "low light" || light_input == "low" || light_input == "medium light" || light_input == "medium" || light_input == "average" || light_input == "bright" || light_input == "hight light" || light_input == "sunny"
  light_input = gets.chomp
  end

  if light_input == "low light" || light_input == "low"
    light = @@low_light
  elsif light_input == "medium light" || light_input == "medium" || light_input == "average"
    light = @@medium_light
  elsif light_input == "bright" || light_input == "high light" || light_input == "sunny"
    light = @@high_light
  end

  puts "Finally, would you describe your attention to plant care as: relaxed, average, or vigilant?"

  until attention_input == "relaxed" || attention_input == "lazy" || attention_input == "average" || attention_input == "medium" || attention_input == "vigilant" || attention_input == "above average"
  attention_input = gets.chomp
  end

  if attention_input == "relaxed" || attention_input == "lazy"
    attention = @@low_maintenance
  elsif attention_input == "average" ||attention_input == "medium"
    attention = @@medium_maintenance
  elsif attention_input == "vigilant" || attention_input == "above average"
    attention = @@high_maintenance
  end

  IndoorJungle::Plant.all.each do |plant|
    if temp.include?(plant) && light.include?(plant) && attention.include?(plant)
      plants << plant
    end
  end

  puts "Thank you for your input! Based on your responses, your ideal plant matches are: "
  sleep(2)
  puts "-----------------------".green
  plants.each do |x|
    if plants.empty?
      puts "I'm sorry but your answers did not result in a match."
    else
    display_plant(x)
    sleep(2.5)
    end
  end

  puts "Would you like to 'redo' your ansers or see the full 'list of plants'? Or 'exit'? "

  until input_2 == "redo" || input_2 == "try again" || input_2 == "list" || input_2 == "list of plants" || input_2 == "plants" || input_2 == "exit" || input_2 == "Exit"
    input_2 = gets.chomp
  end

  if input_2 == "redo" || input_2 == "try again"
    call
  elsif input_2 == "list" || input_2 == "list of plants" || input_2 == "plants"
    display_plants
  else
    puts "Thank you for using your Indoor Jungle Builder!"
    puts "Please Like & Subscribe"
    sleep(3)
    exit
  end
end

#display_plant(plant) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/indoor_jungle/plant_assistant.rb', line 127

def display_plant(plant)
  puts "Plant Name: #{plant.name}".light_green
  puts "Sunlight: #{plant.sunlight[0]}."
  puts "Water: #{plant.water}."
  puts "Temperature: " + "#{plant.temperature}.".capitalize
  puts "#{plant.plant_url}"
  puts "-----------------------".green
end

#display_plantsObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/indoor_jungle/plant_assistant.rb', line 136

def display_plants
  IndoorJungle::Plant.all.each do |plant|
    puts "Plant Name: #{plant.name}".light_green
    puts "#{plant.price_range}".magenta
    puts "Sunlight: #{plant.sunlight[0]}."
    puts "Water: #{plant.water}."
    puts "Temperature: " + "#{plant.temperature}.".capitalize
    puts "#{plant.plant_url}"
    puts "-----------------------".green
  end
  puts "Would you like to 'redo' your ansers or see the full 'list of plants'? "
  input_2 = gets.chomp
  if input_2 == "redo" || input_2 == "try again"
    call
  elsif input_2 == "list" || input_2 == "list of plants" || input_2 == "plants"
    display_plants
  else "Thank you for using your Indoor Jungle Builder!"
    exit
  end
end

#library(klass = IndoorJungle::Plant) ⇒ Object

importing the Song class into this class so we can create a library of all the songs



157
158
159
160
161
# File 'lib/indoor_jungle/plant_assistant.rb', line 157

def library(klass = IndoorJungle::Plant ) #importing the Song class into this class so we can create a library of all the songs
  sorted_library = klass.all.collect{|obj| obj if obj.class == klass}
  sorted_library = sorted_library.delete_if {|obj| obj == nil}
  sorted_library.uniq
end

#make_plantsObject



22
23
24
25
# File 'lib/indoor_jungle/plant_assistant.rb', line 22

def make_plants
  plants_array = IndoorJungle::Scraper.scrape_site(BASE_PATH)
  IndoorJungle::Plant.create_from_collection(plants_array)
end

#sort_plantsObject



163
164
165
166
167
# File 'lib/indoor_jungle/plant_assistant.rb', line 163

def sort_plants
  sort_plants_by_light
  sort_plants_by_temp
  sort_plants_by_maintenance
end

#sort_plants_by_lightObject



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/indoor_jungle/plant_assistant.rb', line 169

def sort_plants_by_light
  #====> plant instances can be in all three
  sorted_plants = self.library
  sorted_plants.each do |plant|
    if plant.sunlight[0].include?("tolerate") || plant.sunlight[0].include?("handle") || plant.sunlight[0].include?("low") || plant.sunlight[0].include?("soft")
      @@low_light << plant
    end
    if !plant.sunlight[0].include?("medium") || plant.sunlight[0].include?("bright")|| plant.sunlight[0].include?("sunny") || plant.sunlight[0].include?("full")
      @@high_light << plant
    end
    if !plant.sunlight[0].include?("Full") || !plant.sunlight[0].include?("sunny")
        @@medium_light << plant
    end
  end
  @@low_light
  @@medium_light
  @@high_light
end

#sort_plants_by_maintenanceObject



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/indoor_jungle/plant_assistant.rb', line 206

def sort_plants_by_maintenance
  sorted_plants = self.library
  sorted_plants.each do |plant|
    if plant.water.include?("Drought") || plant.water.include?("tolerant") || plant.water.include?("tolerate") || plant.water.include?("soil is dry") && !plant.water.include?("do not") && !plant.water.include?("keep")
      @@low_maintenance << plant
    end
    if true
      @@high_maintenance << plant
    end
    if !plant.water.include?("never") && !plant.water.include?("not") && !plant.water.include?("overwater")
      @@medium_maintenance << plant
    end
  end
  @@low_maintenance
  @@medium_maintenance
  @@high_maintenance
end

#sort_plants_by_tempObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/indoor_jungle/plant_assistant.rb', line 188

def sort_plants_by_temp
  sorted_plants = self.library
  sorted_plants.each do |plant|
    if plant.temperature.include?("60-65") || plant.temperature.include?("60") || plant.temperature.include?("60-80") || plant.temperature.include?("Cooler") || plant.temperature.include?("cooler")
      @@cold  << plant
    end
    if plant.temperature.include?("60-80") || plant.temperature.include?("70") ||plant.temperature.include?("75") || plant.temperature.include?("65-90") || plant.temperature.include?("65 - 90") || plant.temperature.include?("65-85")
      @@room_temp << plant
    end
    if plant.temperature.include?("tropical") || plant.temperature.include?("warm") || plant.temperature.include?("80") || plant.temperature.include?("90") || plant.temperature.include?("65-85")
      @@warm << plant
    end
  end
  @@cold
  @@room_temp
  @@warm
end