sea_life 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +21 -0
- data/NOTES.md +61 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/sea_life +5 -0
- data/bin/setup +8 -0
- data/lib/sea_life/animal.rb +30 -0
- data/lib/sea_life/category.rb +20 -0
- data/lib/sea_life/cli.rb +152 -0
- data/lib/sea_life/scraper.rb +67 -0
- data/lib/sea_life/version.rb +3 -0
- data/lib/sea_life.rb +8 -0
- data/sea_life.gemspec +32 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fc61dba00cb2b4117d56e02332de357e66dc30aa5efa1ddcfd98ab66c21d8e64
|
4
|
+
data.tar.gz: 05763a4e36c257e163ccc36daba80b76f2a693859cb41de5fc879368369756d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c729a70383c84e67f948494e221799bf0688c21b48ea9e0ea30660e05c7b92b039c8461874ea7cbf540e11ba69463557929398a80e396c6bf55148567c42ebc
|
7
|
+
data.tar.gz: 4e74ffb7538ea273b50f9debf0e3214bd0a445b38c86793a068882ba9a3e6d0c236285bbad95f42cef4ad704296045352a2fa87bcda03527ef5fcd9b4c2789a3
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at 'mattetress@me.com'. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sea_life (0.1.2)
|
5
|
+
nokogiri (~> 1.8, >= 1.8.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.2)
|
11
|
+
method_source (0.9.0)
|
12
|
+
mini_portile2 (2.3.0)
|
13
|
+
nokogiri (1.8.5)
|
14
|
+
mini_portile2 (~> 2.3.0)
|
15
|
+
pry (0.11.3)
|
16
|
+
coderay (~> 1.1.0)
|
17
|
+
method_source (~> 0.9.0)
|
18
|
+
rake (10.4.2)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
bundler (~> 1.16)
|
25
|
+
nokogiri (~> 1.8.0)
|
26
|
+
pry
|
27
|
+
rake (~> 10.0)
|
28
|
+
sea_life!
|
29
|
+
|
30
|
+
BUNDLED WITH
|
31
|
+
1.16.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 'Matt Etress'
|
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/NOTES.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
CLI Gem Sea Life
|
2
|
+
|
3
|
+
user types in sea_life
|
4
|
+
|
5
|
+
shows a list of categories
|
6
|
+
|
7
|
+
Welcome to Sea Life!
|
8
|
+
Choose a category to learn about:
|
9
|
+
|
10
|
+
1. Cephalopods, crustaceans, & other shellfish
|
11
|
+
2. Corals and other invertebrates
|
12
|
+
3. Marine mammals
|
13
|
+
4. Marine science and ecosystems
|
14
|
+
5. ocean fishes
|
15
|
+
6. sea turtles & reptiles
|
16
|
+
7. seabirds
|
17
|
+
8. sharks & rays
|
18
|
+
|
19
|
+
Please enter your selection:
|
20
|
+
|
21
|
+
INPUT — 2
|
22
|
+
|
23
|
+
Corals and other invertebrates
|
24
|
+
|
25
|
+
info
|
26
|
+
|
27
|
+
choices
|
28
|
+
|
29
|
+
1. American oyster
|
30
|
+
2. blue glaucus
|
31
|
+
3. chilean basket star
|
32
|
+
…
|
33
|
+
|
34
|
+
|
35
|
+
INPUT — 1
|
36
|
+
|
37
|
+
displays american oyster info
|
38
|
+
|
39
|
+
Name: American Oyster
|
40
|
+
Scientific Name: Crassostrea virginica
|
41
|
+
|
42
|
+
Distribution: Sub-tropical to temperate latitudes of the western Atlantic Ocean
|
43
|
+
Ecosystem/Habitat: Soft bottoms
|
44
|
+
Feeding Habits: Filter feeder
|
45
|
+
Conservation Status: Critically Endangered (Very Highly Vulnerable To Extinction)
|
46
|
+
Taxonomy: Class Bivalvia (clams, oysters, and relatives), Family Ostreidae (true oysters)
|
47
|
+
|
48
|
+
The American oyster is an iconic species of the Chesapeake Bay and other coastal waters of eastern North America. Historically, this species was so common and made such large reefs that it was a documented navigation hazard in some areas. Unfortunately, a history of overexploitation, pollution, and physical damage has reduced the American oyster population size to as low as one percent of its original abundance in some areas.
|
49
|
+
|
50
|
+
Type “More” to read more about the American Oyster. You may also type “Back” or “Exit”.
|
51
|
+
|
52
|
+
INPUT — More
|
53
|
+
|
54
|
+
puts
|
55
|
+
American oysters, like all true oysters, live a sessile lifestyle. After a short mobile phase in the plankton, juveniles settle on dead oyster shells or some other hard surface and permanently cement themselves in place. From then on, they build strong, calcium carbonate shells. In this manner, they form very large reefs that provide habitat for several other species of invertebrates and fishes. American oysters are filter feeders that strain plankton and other organic matter from the water above the surface of their reefs. In areas with high oyster densities, they can keep the water nearly free of floating matter. Each American oyster filters approximately 50 gallons of water per day.
|
56
|
+
American oysters reproduce via broadcast spawning, where several females release their eggs and several males release their sperm into the water column at the same time. This behavior increases the likelihood that eggs will be fertilized and decreases the likelihood that the eggs will be eaten by predators near the reef’s surface. These oysters are extremely productive, and a single female may release as many as 150 million eggs throughout her lifetime. When they hatch, all American oysters are male. Most of them reproduce at least once as male, but as they mature, some individuals change to female. This sex change is a result of the difference in energy required to make sperm and eggs. Small individuals can make sperm, while continuing to grow. Larger individuals that have stopped actively growing can afford to utilize their energy to make the larger eggs. Reproduction is triggered by temperature in this species.
|
57
|
+
The American oyster has been overfished and depleted for more than 120 years. The Chesapeake Bay population has been exploited particularly hard, and catches peaked as early as the 1880s. By the early 1900s, it was already depleted. Catch now is approximately one percent of what it was at its 1880s peak. The overexploitation of American oysters has changed the Bay significantly. While the oysters formerly filtered the entire contents of the Bay in short periods of time, that is no longer the case. High levels of pollution in the Chesapeake are exacerbated by the fact that its natural scrubber system has been removed. Though it is likely not at risk of full extinction – thanks to its large range and very high reproductive output – the American oyster is severely depleted throughout its range and no longer provides the habitat and filtration services that it once did.
|
58
|
+
|
59
|
+
|
60
|
+
categories : article.animal-tile
|
61
|
+
category url: site.css("article.animal-tile div.overlay a").attribute("href").value
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# SeaLife
|
2
|
+
|
3
|
+
SeaLife is a simple command line interface gem that scrapes information from a website and provides information about sea creatures.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'sea_life'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install sea_life
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Usage information will be provided later.
|
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/mattetress/sea_life. 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
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
38
|
+
|
39
|
+
## Code of Conduct
|
40
|
+
|
41
|
+
Everyone interacting in the SeaLife project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mattetress/sea_life/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sea_life"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/sea_life
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
class SeaLife::Animal
|
2
|
+
attr_accessor :url, :category, :name, :distribution, :habitat, :habits, :status, :taxonomy, :short_desc, :longer_desc, :scientific_name
|
3
|
+
|
4
|
+
|
5
|
+
@@all = []
|
6
|
+
|
7
|
+
def initialize(info)
|
8
|
+
info.each { |k, v| self.send("#{k}=", v) }
|
9
|
+
@@all << self
|
10
|
+
end
|
11
|
+
|
12
|
+
def category=(category)
|
13
|
+
@category = category
|
14
|
+
category.animals << self
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_info(info)
|
18
|
+
info.each { |k, v| self.send("#{k}=", v) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.all
|
22
|
+
@@all
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.find_by_name(name)
|
26
|
+
self.all.detect { |animal| animal.name == name }
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class SeaLife::Category
|
2
|
+
attr_accessor :name, :url, :animals
|
3
|
+
|
4
|
+
@@all = []
|
5
|
+
|
6
|
+
def initialize(hash)
|
7
|
+
hash.each { |k, v| self.send("#{k}=", v) }
|
8
|
+
self.class.all << self
|
9
|
+
@animals = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all
|
13
|
+
@@all
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find_by_name(name)
|
17
|
+
self.all.detect { |c| c.name == name }
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/sea_life/cli.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
class SeaLife::CLI
|
2
|
+
|
3
|
+
def call
|
4
|
+
puts <<-DOC
|
5
|
+
------------------------------------------------------------
|
6
|
+
|
7
|
+
_________ .____ .__ _____
|
8
|
+
/ _____/ ____ _____ | | |__|/ ____\\____
|
9
|
+
\\_____ \\_/ __ \\\\__ \\ | | | \\ __\\/ __ \\
|
10
|
+
/ \\ ___/ / __ \\| |___| || | \\ ___/
|
11
|
+
/_________/\\____/ _____/ ________\\__||__| \\____/
|
12
|
+
|
13
|
+
|
14
|
+
------------------------------------------------------------
|
15
|
+
|
16
|
+
Welcome!
|
17
|
+
DOC
|
18
|
+
|
19
|
+
list_categories
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
def list_categories
|
26
|
+
puts ""
|
27
|
+
puts "Please choose a category to learn about:"
|
28
|
+
puts ""
|
29
|
+
make_categories if SeaLife::Category.all.size == 0
|
30
|
+
categories = SeaLife::Category.all
|
31
|
+
|
32
|
+
categories.each_with_index do |category, i|
|
33
|
+
puts "#{i + 1}. #{category.name}"
|
34
|
+
end
|
35
|
+
puts ""
|
36
|
+
main_menu(categories)
|
37
|
+
end
|
38
|
+
|
39
|
+
def make_categories
|
40
|
+
SeaLife::Scraper.scrape_categories.each do |category|
|
41
|
+
SeaLife::Category.new(category)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def list_animals(category)
|
46
|
+
puts "Loading animals..."
|
47
|
+
puts ""
|
48
|
+
make_animals_from_category(category) if category.animals.size == 0
|
49
|
+
puts "Please select the animal you'd like to learn about:"
|
50
|
+
animals = []
|
51
|
+
category.animals.each_with_index do |animal, i|
|
52
|
+
puts "#{i + 1}. #{animal.name}"
|
53
|
+
animals << animal
|
54
|
+
end
|
55
|
+
puts ""
|
56
|
+
category_menu(animals)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def make_animals_from_category(category)
|
61
|
+
SeaLife::Scraper.scrape_animals(category)
|
62
|
+
end
|
63
|
+
|
64
|
+
def show_animal(animal)
|
65
|
+
SeaLife::Scraper.scrape_animal_info(animal) unless animal.scientific_name
|
66
|
+
puts ""
|
67
|
+
puts "--------------------------------------------------------------"
|
68
|
+
puts "#{animal.name} (#{animal.scientific_name})"
|
69
|
+
puts ""
|
70
|
+
puts "Distribution: #{animal.distribution}"
|
71
|
+
puts "Ecosystem/Habitat: #{animal.habitat}"
|
72
|
+
puts "Feeding Habits: #{animal.habits}"
|
73
|
+
puts "Conservation Status: #{animal.status}"
|
74
|
+
puts "Taxonomy: #{animal.taxonomy}"
|
75
|
+
puts "--------------------------------------------------------------"
|
76
|
+
puts ""
|
77
|
+
puts "#{animal.short_desc}"
|
78
|
+
puts ""
|
79
|
+
puts "Enter \"MORE\" to continue reading about the #{animal.name}."
|
80
|
+
puts "You may also enter \"BACK\", \"MENU\", or \"EXIT\"."
|
81
|
+
animal_menu(animal)
|
82
|
+
end
|
83
|
+
|
84
|
+
def animal_menu(animal)
|
85
|
+
input = gets.strip.downcase
|
86
|
+
if input == "more"
|
87
|
+
puts ""
|
88
|
+
puts "#{animal.longer_desc}"
|
89
|
+
puts ""
|
90
|
+
puts "Please enter BACK, MENU, or EXIT."
|
91
|
+
animal_menu(animal)
|
92
|
+
elsif input == "back"
|
93
|
+
list_animals(animal.category)
|
94
|
+
elsif input == "menu"
|
95
|
+
list_categories
|
96
|
+
elsif input == "exit"
|
97
|
+
goodbye
|
98
|
+
else
|
99
|
+
puts "Invalid input. Please enter MORE, BACK, MENU, or EXIT."
|
100
|
+
animal_menu(animal)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def main_menu(categories)
|
105
|
+
puts "Please enter the number of a category:"
|
106
|
+
puts "You may also enter \"EXIT\"."
|
107
|
+
input = gets.strip
|
108
|
+
if input.to_i > 0
|
109
|
+
list_animals(categories[input.to_i - 1])
|
110
|
+
elsif input.downcase == "exit"
|
111
|
+
goodbye
|
112
|
+
else
|
113
|
+
puts "Invalid input."
|
114
|
+
main_menu(categories)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def category_menu(animals)
|
119
|
+
puts "Please enter the number of your selection."
|
120
|
+
puts "You may also enter BACK or EXIT"
|
121
|
+
input = gets.strip
|
122
|
+
if input.to_i > 0
|
123
|
+
show_animal(animals[input.to_i - 1])
|
124
|
+
elsif input.downcase == "back"
|
125
|
+
list_categories
|
126
|
+
elsif input.downcase == "exit"
|
127
|
+
goodbye
|
128
|
+
else
|
129
|
+
puts "Invalid input."
|
130
|
+
category_menu(animals)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
def goodbye
|
137
|
+
puts <<-DOC
|
138
|
+
------------------------------------------------------------
|
139
|
+
|
140
|
+
_________ .____ .__ _____
|
141
|
+
/ _____/ ____ _____ | | |__|/ ____\\____
|
142
|
+
\\_____ \\_/ __ \\\\__ \\ | | | \\ __\\/ __ \\
|
143
|
+
/ \\ ___/ / __ \\| |___| || | \\ ___/
|
144
|
+
/_________/\\____/ _____/ ________\\__||__| \\____/
|
145
|
+
See you soon!
|
146
|
+
|
147
|
+
------------------------------------------------------------
|
148
|
+
DOC
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class SeaLife::Scraper
|
2
|
+
|
3
|
+
BASE_URL = "https://oceana.org"
|
4
|
+
|
5
|
+
def self.scrape_categories #Scrapes oceana and returns array of categories
|
6
|
+
categories = []
|
7
|
+
doc = Nokogiri::HTML(open(BASE_URL + "/marine-life"))
|
8
|
+
doc.css("article.animal-tile").each do |item|
|
9
|
+
category = {}
|
10
|
+
category[:url] = item.css("div.overlay a").attribute("href").value
|
11
|
+
category[:name] = item.css("div.copy h1").text
|
12
|
+
categories << category unless category[:name] == "Marine Science and Ecosystems"
|
13
|
+
end
|
14
|
+
categories
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.scrape_animals(category)
|
18
|
+
doc = Nokogiri::HTML(open(BASE_URL + category.url))
|
19
|
+
doc.css("article").each do |animal|
|
20
|
+
animal_info = {}
|
21
|
+
animal_info[:category] = category
|
22
|
+
animal_info[:name] = animal.css("div.copy h1").text
|
23
|
+
animal_info[:url] = animal.css("div.overlay a").attribute("href").value
|
24
|
+
SeaLife::Animal.new(animal_info)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# def self.scrape_animals(category_url)
|
29
|
+
# doc = Nokogiri::HTML(open(BASE_URL + category_url))
|
30
|
+
# doc.css("article").each do |animal|
|
31
|
+
# SeaLife::Animal.new(SeaLife::Scraper.scrape_animals_from_url("#{animal.css("div.overlay a").attribute("href").value}"))
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
|
35
|
+
def self.scrape_animal_info(animal)
|
36
|
+
doc = Nokogiri::HTML(open(BASE_URL + animal.url))
|
37
|
+
animal_info = {}
|
38
|
+
# animal_info[:category] = doc.css("section.subpage-header div h2").text
|
39
|
+
# animal_info[:name] = doc.css("section.subpage-header div h1").text
|
40
|
+
animal_info[:scientific_name] = doc.css("section.subpage-header div p").text
|
41
|
+
animal_info[:short_desc] = doc.css("div.animal-description-contain p").text
|
42
|
+
animal_info[:longer_desc] = ""
|
43
|
+
doc.css("section.animal-secondary div.flex-item-2 p").each do |paragraph|
|
44
|
+
break if paragraph.text == "Additional Resources:"
|
45
|
+
animal_info[:longer_desc] += "\n\n #{paragraph.text}"
|
46
|
+
end
|
47
|
+
i = 0
|
48
|
+
while i < doc.css("div.animal-details-side h2").size - 1 do
|
49
|
+
info_cat = doc.css("div.animal-details-side h2")[i].text.strip.downcase
|
50
|
+
info = doc.css("div.animal-details-side p")[i].text.strip
|
51
|
+
case info_cat
|
52
|
+
when "ecosystem/habitat"
|
53
|
+
animal_info[:habitat] = info
|
54
|
+
when "feeding habits"
|
55
|
+
animal_info[:habits] = info
|
56
|
+
when "conservation status"
|
57
|
+
animal_info[:status] = info
|
58
|
+
else
|
59
|
+
animal_info[info_cat.to_sym] = info
|
60
|
+
end
|
61
|
+
|
62
|
+
i += 1
|
63
|
+
end
|
64
|
+
animal.add_info(animal_info)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
data/lib/sea_life.rb
ADDED
data/sea_life.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "sea_life/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sea_life"
|
8
|
+
spec.version = SeaLife::VERSION
|
9
|
+
spec.authors = ["Matt Etress"]
|
10
|
+
spec.email = ["mattetress@me.com"]
|
11
|
+
|
12
|
+
spec.summary = "A simple CLI Gem that provides information about various sea creatures."
|
13
|
+
spec.homepage = "https://github.com/mattetress/sea_life"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "bin"
|
24
|
+
spec.executables = ["sea_life"]
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
spec.add_dependency "nokogiri", "~> 1.8", ">= 1.8.0"
|
31
|
+
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sea_life
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Etress
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-16 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: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.8.0
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.8'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.8.0
|
75
|
+
description:
|
76
|
+
email:
|
77
|
+
- mattetress@me.com
|
78
|
+
executables:
|
79
|
+
- sea_life
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- ".gitignore"
|
84
|
+
- CODE_OF_CONDUCT.md
|
85
|
+
- Gemfile
|
86
|
+
- Gemfile.lock
|
87
|
+
- LICENSE.txt
|
88
|
+
- NOTES.md
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bin/console
|
92
|
+
- bin/sea_life
|
93
|
+
- bin/setup
|
94
|
+
- lib/sea_life.rb
|
95
|
+
- lib/sea_life/animal.rb
|
96
|
+
- lib/sea_life/category.rb
|
97
|
+
- lib/sea_life/cli.rb
|
98
|
+
- lib/sea_life/scraper.rb
|
99
|
+
- lib/sea_life/version.rb
|
100
|
+
- sea_life.gemspec
|
101
|
+
homepage: https://github.com/mattetress/sea_life
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.7.7
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: A simple CLI Gem that provides information about various sea creatures.
|
125
|
+
test_files: []
|