plant_toxicity 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e879c7994be042bfdc68380906e3b70b80c2f66
4
+ data.tar.gz: ee4cb46a3fa39e57ad930a6d55274de3bbde32c0
5
+ SHA512:
6
+ metadata.gz: 89597d8ce63acbb4d99b7bc9ef5869b2cd1643522cab2360605cba7b12d41582cb90855f92fcbc723ae0f12464d1ec7d2ef9dcf4fe0591727d15bc38ad6f3e9e
7
+ data.tar.gz: e3b3c26bed778fa49bfe7dded273f4af4d2285e5da9f438355b8025649d223e98964b20b894da4e11321e94baaf63d631952315690d2da89db3d41e4e76b1972
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 'Veronica Miller'
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # PlantToxicity
2
+
3
+ This Ruby Gem contains a CLI that can provide details about common plants, including their toxicity to certain pets (dogs, cats, and horses). Based on information from the ASPCA website, the user can obtain a list of plants for any letter of the alphabet (A-Z), and then additional details about specific plants in the list can be requested. These details may include, as available: other common names, scientific name, toxicity, non-toxicity, and clinical signs of poisoning.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'plant_toxicity'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install plant_toxicity
20
+
21
+ ## Usage
22
+
23
+ After installation, type 'plant-toxicity' and then follow the prompts.
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/'vmcmiller-72282'/plant_toxicity. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "./lib/plant_toxicity"
4
+ require "bundler/setup"
5
+
6
+ PlantToxicity::CLI.new.call
@@ -0,0 +1,9 @@
1
+ require_relative "plant_toxicity/version"
2
+ require_relative './plant_toxicity/cli'
3
+ require_relative './plant_toxicity/list'
4
+ require_relative './plant_toxicity/plant'
5
+ require_relative './plant_toxicity/scraper'
6
+
7
+ require 'nokogiri'
8
+ require 'open-uri'
9
+ require 'pry'
@@ -0,0 +1,88 @@
1
+ class PlantToxicity::CLI
2
+
3
+ def call
4
+ puts "Welcome to the Plant Toxicity to Pets tool!"
5
+ puts "-------------------------------------------"
6
+ puts "It can tell you whether various common plants are toxic to dogs, cats, and horses."
7
+ list_plants_by_letter
8
+ puts "-------------------------------------------"
9
+ puts "Thank you for using the tool! Goodbye."
10
+ exit
11
+ end
12
+
13
+ def list_plants_by_letter
14
+ puts "The plants are listed alphabetically by letter, according to the first letter in each plant's name."
15
+ puts "To see a list of plants, enter a letter from A to Z. Enter 'exit' to end the session."
16
+ input = nil
17
+ until input == "exit"
18
+ input = gets.strip.downcase
19
+ if input.match(/\b[a-z]\b/)
20
+ list = PlantToxicity::List.all.detect {|list| list.letter == input.upcase}
21
+ if !list
22
+ list = PlantToxicity::List.new(input.upcase)
23
+ end
24
+ display_list(list)
25
+ puts "Enter a letter from A to Z to see another list of plants, or enter 'exit' to end the session."
26
+ elsif input == "exit"
27
+ break
28
+ else
29
+ puts "Sorry, that is not a valid option. Enter a letter or 'exit'."
30
+ end
31
+ end
32
+ end
33
+
34
+ def display_list(list)
35
+ if !list.plants.empty?
36
+ puts "These are the plants that begin with the letter '#{list.letter}':"
37
+ list.plants.each.with_index(1) do |plant, i|
38
+ puts "#{i}. #{plant.name}"
39
+ end
40
+ puts "-------------------------------------------"
41
+ puts "Would you like to see more details about a plant in this list? (Y/N)"
42
+ input = nil
43
+ until input == "n"
44
+ input = gets.strip.downcase
45
+ if input == "y"
46
+ show_details(list)
47
+ puts "Would you like more information about another plant in this list? (Y/N)"
48
+ elsif input == "n"
49
+ break
50
+ else
51
+ puts "Sorry, that is not a valid option. Please enter Y or N."
52
+ end
53
+ end
54
+ else
55
+ puts "-------------------------------------------"
56
+ puts "There are no plants that begin with the letter '#{list.letter}'."
57
+ puts "-------------------------------------------"
58
+ end
59
+ end
60
+
61
+ def show_details(list)
62
+ puts "Please enter the plant's number. (1-#{list.plants.length})"
63
+ input = gets.strip.to_i
64
+ until input >= 1 && input <= list.plants.length
65
+ puts "Sorry, that is not a valid option. Please enter a number."
66
+ input = gets.strip.to_i
67
+ end
68
+ plant = list.select_plant(input-1)
69
+ display_plant(plant)
70
+ end
71
+
72
+ def display_plant(plant)
73
+ header = "Details for #{plant.name}:"
74
+ puts "-" * header.length
75
+ puts header
76
+ puts "-" * header.length
77
+ plant.details.each do |detail|
78
+ puts "Other Names: #{plant.other_names}" if detail == :@other_names
79
+ puts "Scientific Name: #{plant.scientific_name}" if detail == :@scientific_name
80
+ puts "Toxicity: #{plant.toxicity}" if detail == :@toxicity
81
+ puts "Non-Toxicity: #{plant.non_toxicity}" if detail == :@non_toxicity
82
+ puts "Clinical Signs: #{plant.clinical_signs}" if detail == :@clinical_signs
83
+ puts "" if detail != plant.details.last
84
+ end
85
+ puts "-" * header.length
86
+ end
87
+
88
+ end
@@ -0,0 +1,24 @@
1
+ class PlantToxicity::List
2
+
3
+ attr_accessor :letter, :plants
4
+ attr_reader :scraper
5
+
6
+ @@all = []
7
+
8
+ def initialize(letter)
9
+ @letter = letter.upcase
10
+ @plants = PlantToxicity::Scraper.get_list(@letter)
11
+ @@all << self
12
+ end
13
+
14
+ def self.all
15
+ @@all
16
+ end
17
+
18
+ def select_plant(input)
19
+ plant = self.plants[input]
20
+ PlantToxicity::Scraper.get_plant_details(plant)
21
+ plant
22
+ end
23
+
24
+ end
@@ -0,0 +1,16 @@
1
+ class PlantToxicity::Plant
2
+
3
+ attr_accessor :name, :url, :scientific_name, :other_names, :toxicity, :non_toxicity, :clinical_signs
4
+
5
+ def initialize(name, url)
6
+ @name = name
7
+ @url = url
8
+ end
9
+
10
+ def details
11
+ [:@other_names, :@scientific_name, :@toxicity, :@non_toxicity, :@clinical_signs].reject do |var|
12
+ self.instance_variable_get(var) == nil || self.instance_variable_get(var) == ""
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,49 @@
1
+ class PlantToxicity::Scraper
2
+
3
+ URL_BASE = "https://www.aspca.org"
4
+
5
+ def self.get_list(letter)
6
+ plants = []
7
+ doc = Nokogiri::HTML(open(URL_BASE + "/pet-care/animal-poison-control/toxic-and-non-toxic-plants"))
8
+ letter_details = doc.search("div.view-content span.views-summary a").detect {|letters| letters.text == letter.upcase}
9
+ if letter_details != nil
10
+ pages = []
11
+ pages << URL_BASE + letter_details.attribute("href").value
12
+ Nokogiri::HTML(open(pages.first)).search("li.pager-item").each {|page| pages << URL_BASE + page.search("a").attribute("href").value}
13
+ if pages.length > 1
14
+ next_page = Nokogiri::HTML(open(pages.last)).search("ul.pager li").detect {|link| link.attribute("class").value == "pager-next"}
15
+ while next_page
16
+ pages << URL_BASE + next_page.search("a").attribute("href").value
17
+ next_page = Nokogiri::HTML(open(pages.last)).search("ul.pager li").detect {|link| link.attribute("class").value == "pager-next"}
18
+ end
19
+ end
20
+ pages.each do |page|
21
+ Nokogiri::HTML(open(page)).search("div.views-field-title a").each do |plant|
22
+ plants << PlantToxicity::Plant.new(plant.text, URL_BASE + plant.attribute("href").value)
23
+ end
24
+ end
25
+ end
26
+ plants
27
+ end
28
+
29
+ def self.get_plant_details(plant)
30
+ Nokogiri::HTML(open(plant.url)).search("div.pane-entity-field div.field-items").each do |field|
31
+ if field.search("span.label-inline-format-label").text == "Scientific Name:"
32
+ plant.scientific_name = field.search("span.values").text.strip
33
+ end
34
+ if field.search("span.label-inline-format-label").text == "Additional Common Names:"
35
+ plant.other_names = field.search("span.values").text.strip
36
+ end
37
+ if field.search("span.label-inline-format-label").text == "Toxicity:"
38
+ plant.toxicity = field.search("span.values").text.strip
39
+ end
40
+ if field.search("span.label-inline-format-label").text == "Non-Toxicity:"
41
+ plant.non_toxicity = field.search("span.values").text.strip
42
+ end
43
+ if field.search("span.label-inline-format-label").text == "Clinical Signs:"
44
+ plant.clinical_signs = field.search("span.values").text.strip
45
+ end
46
+ end
47
+ end
48
+
49
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plant_toxicity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Veronica Miller'"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-03 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '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'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: As prompted by the user, it can list all plants starting with a given
70
+ letter of the alphabet as well as provide further details about any plant listed.
71
+ email:
72
+ - "'vmcmiller@gmail.com'"
73
+ executables:
74
+ - plant-toxicity
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - LICENSE.txt
79
+ - README.md
80
+ - bin/plant-toxicity
81
+ - lib/plant_toxicity.rb
82
+ - lib/plant_toxicity/cli.rb
83
+ - lib/plant_toxicity/list.rb
84
+ - lib/plant_toxicity/plant.rb
85
+ - lib/plant_toxicity/scraper.rb
86
+ homepage: http://rubygems.org/gems/plant-toxicity
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.6.11
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Provides details about common plants and their toxicity to pets.
110
+ test_files: []