sea_life 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc61dba00cb2b4117d56e02332de357e66dc30aa5efa1ddcfd98ab66c21d8e64
4
- data.tar.gz: 05763a4e36c257e163ccc36daba80b76f2a693859cb41de5fc879368369756d7
3
+ metadata.gz: 1fe7f094b290aa3861eb0b8152902d349da9a4ba025348465821ce4f88725c42
4
+ data.tar.gz: 840b9b42cc6541a8b81f46e3aa4c8466efe5456fa3f2601461a916ca0dcd5f30
5
5
  SHA512:
6
- metadata.gz: 3c729a70383c84e67f948494e221799bf0688c21b48ea9e0ea30660e05c7b92b039c8461874ea7cbf540e11ba69463557929398a80e396c6bf55148567c42ebc
7
- data.tar.gz: 4e74ffb7538ea273b50f9debf0e3214bd0a445b38c86793a068882ba9a3e6d0c236285bbad95f42cef4ad704296045352a2fa87bcda03527ef5fcd9b4c2789a3
6
+ metadata.gz: d07de2328538b5dbb32206c8f44912f6d295a44484ad37a9365705d0802a42e63071add1f963ef02ae8d31a2023380f8f974b00a5398d9a614bc6c68056f590f
7
+ data.tar.gz: ffe95daaa3132548b9d0a0b3978c84135350714a27c12fcdc300bad46b686ffa2749bf62f4d3c1ede247ca71363ca6daea18651b712147604b22ba085fdfeba2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sea_life (0.1.2)
4
+ sea_life (0.1.3)
5
5
  nokogiri (~> 1.8, >= 1.8.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,26 +1,20 @@
1
1
  # SeaLife
2
2
 
3
- SeaLife is a simple command line interface gem that scrapes information from a website and provides information about sea creatures.
3
+ SeaLife is a simple CLI Gem that scrapes information from Oceana's Marine Life Encyclopedia and provides information about sea creatures.
4
4
 
5
5
  ## Installation
6
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:
7
+ Gem can be installed by:
18
8
 
19
9
  $ gem install sea_life
20
10
 
21
11
  ## Usage
22
12
 
23
- Usage information will be provided later.
13
+ Run the CLI by typing:
14
+
15
+ $ sea_life
16
+
17
+ After the CLI has loaded you will be presented with a list of categories. Enter the number of the category you'd like to see and press enter. The application will present you with a list of animals that belong to that category. You can then choose one of these animals by entering the number of your selection.
24
18
 
25
19
  ## Development
26
20
 
@@ -34,7 +28,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/mattet
34
28
 
35
29
  ## License
36
30
 
37
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
31
+ The gem is available as open source under the terms of the [MIT License](https://github.com/mattetress/sea_life/blob/master/LICENSE.txt).
38
32
 
39
33
  ## Code of Conduct
40
34
 
@@ -1,11 +1,10 @@
1
1
  class SeaLife::Animal
2
- attr_accessor :url, :category, :name, :distribution, :habitat, :habits, :status, :taxonomy, :short_desc, :longer_desc, :scientific_name
3
-
4
-
2
+ attr_accessor :url, :name, :distribution, :habitat, :habits, :status, :taxonomy, :short_desc, :longer_desc, :scientific_name
3
+ attr_reader :category
5
4
  @@all = []
6
5
 
7
6
  def initialize(info)
8
- info.each { |k, v| self.send("#{k}=", v) }
7
+ add_info(info)
9
8
  @@all << self
10
9
  end
11
10
 
@@ -25,6 +24,4 @@ class SeaLife::Animal
25
24
  def self.find_by_name(name)
26
25
  self.all.detect { |animal| animal.name == name }
27
26
  end
28
-
29
-
30
27
  end
@@ -1,37 +1,34 @@
1
1
  class SeaLife::CLI
2
2
 
3
3
  def call
4
- puts <<-DOC
5
- ------------------------------------------------------------
6
-
7
- _________ .____ .__ _____
8
- / _____/ ____ _____ | | |__|/ ____\\____
9
- \\_____ \\_/ __ \\\\__ \\ | | | \\ __\\/ __ \\
10
- / \\ ___/ / __ \\| |___| || | \\ ___/
11
- /_________/\\____/ _____/ ________\\__||__| \\____/
12
-
13
-
14
- ------------------------------------------------------------
15
-
16
- Welcome!
17
- DOC
4
+ puts "------------------------------------------------------------"
5
+ puts ""
6
+ puts " _________ .____ .__ _____"
7
+ puts " / _____/ ____ _____ | | |__|/ ____\\____"
8
+ puts " \\_____ \\_/ __ \\\\__ \\ | | | \\ __\\/ __ \\"
9
+ puts " / \\ ___/ / __ \\| |___| || | \\ ___/"
10
+ puts " /_________/\\____/ _____/ ________\\__||__| \\____/"
11
+ puts ""
12
+ puts ""
13
+ puts "------------------------------------------------------------"
14
+ puts ""
15
+ puts "Welcome!"
18
16
 
19
17
  list_categories
20
-
21
18
  end
22
19
 
23
-
24
-
25
20
  def list_categories
26
21
  puts ""
27
22
  puts "Please choose a category to learn about:"
28
23
  puts ""
24
+
29
25
  make_categories if SeaLife::Category.all.size == 0
30
26
  categories = SeaLife::Category.all
31
27
 
32
28
  categories.each_with_index do |category, i|
33
29
  puts "#{i + 1}. #{category.name}"
34
30
  end
31
+
35
32
  puts ""
36
33
  main_menu(categories)
37
34
  end
@@ -45,14 +42,19 @@ DOC
45
42
  def list_animals(category)
46
43
  puts "Loading animals..."
47
44
  puts ""
45
+
48
46
  make_animals_from_category(category) if category.animals.size == 0
47
+
49
48
  puts "Please select the animal you'd like to learn about:"
49
+
50
50
  animals = []
51
51
  category.animals.each_with_index do |animal, i|
52
52
  puts "#{i + 1}. #{animal.name}"
53
53
  animals << animal
54
54
  end
55
+
55
56
  puts ""
57
+
56
58
  category_menu(animals)
57
59
  end
58
60
 
@@ -63,6 +65,7 @@ DOC
63
65
 
64
66
  def show_animal(animal)
65
67
  SeaLife::Scraper.scrape_animal_info(animal) unless animal.scientific_name
68
+
66
69
  puts ""
67
70
  puts "--------------------------------------------------------------"
68
71
  puts "#{animal.name} (#{animal.scientific_name})"
@@ -78,11 +81,13 @@ DOC
78
81
  puts ""
79
82
  puts "Enter \"MORE\" to continue reading about the #{animal.name}."
80
83
  puts "You may also enter \"BACK\", \"MENU\", or \"EXIT\"."
84
+
81
85
  animal_menu(animal)
82
86
  end
83
87
 
84
88
  def animal_menu(animal)
85
89
  input = gets.strip.downcase
90
+
86
91
  if input == "more"
87
92
  puts ""
88
93
  puts "#{animal.longer_desc}"
@@ -104,8 +109,10 @@ DOC
104
109
  def main_menu(categories)
105
110
  puts "Please enter the number of a category:"
106
111
  puts "You may also enter \"EXIT\"."
112
+
107
113
  input = gets.strip
108
- if input.to_i > 0
114
+
115
+ if input.to_i > 0 && input.to_i <= categories.size
109
116
  list_animals(categories[input.to_i - 1])
110
117
  elsif input.downcase == "exit"
111
118
  goodbye
@@ -118,8 +125,10 @@ DOC
118
125
  def category_menu(animals)
119
126
  puts "Please enter the number of your selection."
120
127
  puts "You may also enter BACK or EXIT"
128
+
121
129
  input = gets.strip
122
- if input.to_i > 0
130
+
131
+ if input.to_i > 0 && input.to_i <= animals.size
123
132
  show_animal(animals[input.to_i - 1])
124
133
  elsif input.downcase == "back"
125
134
  list_categories
@@ -131,22 +140,16 @@ DOC
131
140
  end
132
141
  end
133
142
 
134
-
135
-
136
143
  def goodbye
137
- puts <<-DOC
138
- ------------------------------------------------------------
139
-
140
- _________ .____ .__ _____
141
- / _____/ ____ _____ | | |__|/ ____\\____
142
- \\_____ \\_/ __ \\\\__ \\ | | | \\ __\\/ __ \\
143
- / \\ ___/ / __ \\| |___| || | \\ ___/
144
- /_________/\\____/ _____/ ________\\__||__| \\____/
145
- See you soon!
146
-
147
- ------------------------------------------------------------
148
- DOC
149
-
144
+ puts "------------------------------------------------------------"
145
+ puts ""
146
+ puts " _________ .____ .__ _____"
147
+ puts " / _____/ ____ _____ | | |__|/ ____\\____"
148
+ puts " \\_____ \\_/ __ \\\\__ \\ | | | \\ __\\/ __ \\"
149
+ puts " / \\ ___/ / __ \\| |___| || | \\ ___/"
150
+ puts " /_________/\\____/ _____/ ________\\__||__| \\____/"
151
+ puts " See you soon!"
152
+ puts ""
153
+ puts "------------------------------------------------------------"
150
154
  end
151
-
152
155
  end
@@ -5,17 +5,20 @@ class SeaLife::Scraper
5
5
  def self.scrape_categories #Scrapes oceana and returns array of categories
6
6
  categories = []
7
7
  doc = Nokogiri::HTML(open(BASE_URL + "/marine-life"))
8
+
8
9
  doc.css("article.animal-tile").each do |item|
9
10
  category = {}
10
11
  category[:url] = item.css("div.overlay a").attribute("href").value
11
12
  category[:name] = item.css("div.copy h1").text
12
13
  categories << category unless category[:name] == "Marine Science and Ecosystems"
13
14
  end
15
+
14
16
  categories
15
17
  end
16
18
 
17
19
  def self.scrape_animals(category)
18
20
  doc = Nokogiri::HTML(open(BASE_URL + category.url))
21
+
19
22
  doc.css("article").each do |animal|
20
23
  animal_info = {}
21
24
  animal_info[:category] = category
@@ -25,29 +28,24 @@ class SeaLife::Scraper
25
28
  end
26
29
  end
27
30
 
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
31
  def self.scrape_animal_info(animal)
36
32
  doc = Nokogiri::HTML(open(BASE_URL + animal.url))
33
+
37
34
  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
35
  animal_info[:scientific_name] = doc.css("section.subpage-header div p").text
41
36
  animal_info[:short_desc] = doc.css("div.animal-description-contain p").text
42
37
  animal_info[:longer_desc] = ""
38
+
43
39
  doc.css("section.animal-secondary div.flex-item-2 p").each do |paragraph|
44
40
  break if paragraph.text == "Additional Resources:"
45
41
  animal_info[:longer_desc] += "\n\n #{paragraph.text}"
46
42
  end
43
+
47
44
  i = 0
48
45
  while i < doc.css("div.animal-details-side h2").size - 1 do
49
46
  info_cat = doc.css("div.animal-details-side h2")[i].text.strip.downcase
50
47
  info = doc.css("div.animal-details-side p")[i].text.strip
48
+
51
49
  case info_cat
52
50
  when "ecosystem/habitat"
53
51
  animal_info[:habitat] = info
@@ -61,6 +59,7 @@ class SeaLife::Scraper
61
59
 
62
60
  i += 1
63
61
  end
62
+
64
63
  animal.add_info(animal_info)
65
64
  end
66
65
 
@@ -1,3 +1,3 @@
1
1
  module SeaLife
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sea_life
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Etress
@@ -85,7 +85,6 @@ files:
85
85
  - Gemfile
86
86
  - Gemfile.lock
87
87
  - LICENSE.txt
88
- - NOTES.md
89
88
  - README.md
90
89
  - Rakefile
91
90
  - bin/console
data/NOTES.md DELETED
@@ -1,61 +0,0 @@
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