cat_breeds 0.1.1
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +21 -0
- data/NOTES.md +76 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/cat-breeds +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cat_breeds.gemspec +31 -0
- data/lib/cat_breeds/cats.rb +22 -0
- data/lib/cat_breeds/cli.rb +159 -0
- data/lib/cat_breeds/scraper.rb +46 -0
- data/lib/cat_breeds/version.rb +3 -0
- data/lib/cat_breeds.rb +9 -0
- data/spec.md +8 -0
- metadata +135 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: dacb954019aef48383630c673a252ee1230fb5d0a58fb267cf5a2281a1f1a2f1
|
|
4
|
+
data.tar.gz: '08958fc9f0792a9e75d8a47ea15cda683a209bf469169541680cfee473a55dcc'
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0aeb4f87af6bf5f6a04af10aadf219899df1f0b55f6e92d43a04546e808d134fa74d5cb85c51ba1d75d8c9fb21f20b4fd3ddc5e213168db3d06e00156a583d23
|
|
7
|
+
data.tar.gz: 0771c4e8961cedb02b7f9a7340ffeb664641011cf16b1bd31f8ae9c7ea295b076c41f574fac40d13277f2a94496069f415cb027ffd0481325d4c65cd392e81ed
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
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 PeejFrias@Gmail.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,45 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
cat_breeds (0.1.0)
|
|
5
|
+
nokogiri
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
coderay (1.1.2)
|
|
11
|
+
diff-lcs (1.3)
|
|
12
|
+
method_source (0.9.0)
|
|
13
|
+
mini_portile2 (2.3.0)
|
|
14
|
+
nokogiri (1.8.1)
|
|
15
|
+
mini_portile2 (~> 2.3.0)
|
|
16
|
+
pry (0.11.3)
|
|
17
|
+
coderay (~> 1.1.0)
|
|
18
|
+
method_source (~> 0.9.0)
|
|
19
|
+
rake (10.5.0)
|
|
20
|
+
rspec (3.7.0)
|
|
21
|
+
rspec-core (~> 3.7.0)
|
|
22
|
+
rspec-expectations (~> 3.7.0)
|
|
23
|
+
rspec-mocks (~> 3.7.0)
|
|
24
|
+
rspec-core (3.7.1)
|
|
25
|
+
rspec-support (~> 3.7.0)
|
|
26
|
+
rspec-expectations (3.7.0)
|
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
28
|
+
rspec-support (~> 3.7.0)
|
|
29
|
+
rspec-mocks (3.7.0)
|
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
31
|
+
rspec-support (~> 3.7.0)
|
|
32
|
+
rspec-support (3.7.0)
|
|
33
|
+
|
|
34
|
+
PLATFORMS
|
|
35
|
+
ruby
|
|
36
|
+
|
|
37
|
+
DEPENDENCIES
|
|
38
|
+
bundler (~> 1.16)
|
|
39
|
+
cat_breeds!
|
|
40
|
+
pry
|
|
41
|
+
rake (~> 10.0)
|
|
42
|
+
rspec (~> 3.0)
|
|
43
|
+
|
|
44
|
+
BUNDLED WITH
|
|
45
|
+
1.16.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 PJ Frias
|
|
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,76 @@
|
|
|
1
|
+
|
|
2
|
+
Project Outline
|
|
3
|
+
|
|
4
|
+
Provide a CLI
|
|
5
|
+
CLI must provide access to data from a web page.
|
|
6
|
+
The data provided must go at least one level deep, generally by showing the user a list of available data and then being able to drill down into a specific item.
|
|
7
|
+
The CLI application can not be a Music CLI application as that is too similiar to the other OO Ruby final project. Also please refrain from using Kickstarter as that was used for the scraping 'code along'. Look at the example domains below for inspiration.
|
|
8
|
+
Use good OO design patterns. You should be creating a collection of objects - not hashes.
|
|
9
|
+
For bonus points, instead of just creating an application, create a gem and for extra bonus points try publishing it to RubyGems.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Instructions -
|
|
13
|
+
Watch this video walkthrough of building a CLI Gem called Daily Deal before you begin.
|
|
14
|
+
Create a new repository on GitHub for your application, ie: name-cli-app.
|
|
15
|
+
When you create the CLI app for your assessment, add the spec.md file from this repo to the root directory of the project, commit it to Git and push it up to GitHub.
|
|
16
|
+
Build your application. Make sure to commit early and commit often. Commit messages should be meaningful (clearly describe what you're doing in the commit) and accurate (there should be nothing in the commit that doesn't match the description in the commit message). Good rule of thumb is to commit every 3-7 mins of actual coding time. Most of your commits should have under 15 lines of code and a 2 line commit is perfectly acceptable. This is important and you'll be graded on this.
|
|
17
|
+
Make sure to create a good README.md with a short description, install instructions, a contributors guide and a link to the license for your code.
|
|
18
|
+
While you're working on it, record a 30 min coding session with your favorite screen capture tool. During the session, either think out loud or not. It's up to you. You don't need to submit the video, but we may ask for it at a later time.
|
|
19
|
+
Make sure to check each box in your spec.md (replace the space between the square braces with an x) and explain next to each one how you've met the requirement before you submit your project.
|
|
20
|
+
Prepare a video demo (narration helps!) describing how a user would interact with your working gem.
|
|
21
|
+
Write a blog post about the project and process.
|
|
22
|
+
On Learn, submit links to the GitHub repository for your app, your video demo, and your blog post each to the corresponding textbox in the right rail, and hit "I'm done" to wrap it up.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
-----
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Project Planning:
|
|
29
|
+
|
|
30
|
+
----- File Responsibilities -----
|
|
31
|
+
|
|
32
|
+
cli.rb
|
|
33
|
+
call
|
|
34
|
+
make_cats - Create object array of cats using scrape_index_page
|
|
35
|
+
add_attributes_to_podcasts - Add data to each object using stitcher url via scrape_profile_page
|
|
36
|
+
puts "Cats are neat! Check out all the different cat breeds!"
|
|
37
|
+
list_all
|
|
38
|
+
goodbye
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
list_all
|
|
42
|
+
puts all cats in alphabetical order in numbered list
|
|
43
|
+
puts "Which breed would you like to learn more about?"
|
|
44
|
+
puts "Enter the number or the name of the breed. Type exit to close."
|
|
45
|
+
input = gets.strip
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
scraper.rb
|
|
50
|
+
scrape_index_page(url)
|
|
51
|
+
breed[:name] =
|
|
52
|
+
breed[:page_url] =
|
|
53
|
+
|
|
54
|
+
scrape_profile_page(url)
|
|
55
|
+
|
|
56
|
+
breed[:size] =
|
|
57
|
+
breed[:coat] =
|
|
58
|
+
breed[:color] =
|
|
59
|
+
size/coat/color
|
|
60
|
+
key = doc.css("div.statsDef-content-list-item-label").first.text
|
|
61
|
+
value = doc.css("div.statsDef-content-list-item-value").first.text.gsub("\n","").strip
|
|
62
|
+
|
|
63
|
+
breed[:description] = doc.css("div.blurb-content-hd-titleMd p").text
|
|
64
|
+
breed[:fun_fact] = doc.css("div.quarantine").first.text.gsub("\n","").strip
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
breed[:similar] =
|
|
68
|
+
Similar Cat Breeds
|
|
69
|
+
(For Each)
|
|
70
|
+
breed = doc.css("a.callout").first.css("img").first.attr("alt")
|
|
71
|
+
url = BASE_PATH + "/#{breed}"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
cat.rb
|
|
75
|
+
|
|
76
|
+
attr_accessor :name, :page_url, :size, :coat, :color, :description, :fun_fact, :similar
|
data/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# CatBreeds
|
|
2
|
+
|
|
3
|
+
A simple command line interface gem that scrapes a website and provides information on cat breeds to the user.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem install cat_breeds
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Type the command below to start the cat_breeds CLI and start exploring the many amazing breeds of cats!
|
|
14
|
+
|
|
15
|
+
$ cat-breeds
|
|
16
|
+
|
|
17
|
+
Select a cat from the main menu by entering either its breed name or menu number. Once you've selected a cat breed, you will be able to select further details to learn more about that breed. When you select a specific category, you can either go back and look into another category for that same cat breed, or you can go back to the home menu and learn about a different cat breed. Enter exit at any point while using cat_breeds to close out of the gem CLI.
|
|
18
|
+
|
|
19
|
+
## Development
|
|
20
|
+
|
|
21
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
22
|
+
|
|
23
|
+
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).
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cat_breeds. 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.
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
32
|
+
|
|
33
|
+
## Code of Conduct
|
|
34
|
+
|
|
35
|
+
Everyone interacting in the CatBreeds project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ThePeej/cat-breeds-cli-gem/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/cat-breeds
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "cat_breeds"
|
|
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
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/cat_breeds.gemspec
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "cat_breeds/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "cat_breeds"
|
|
8
|
+
spec.version = CatBreeds::VERSION
|
|
9
|
+
spec.authors = ["PJ Frias"]
|
|
10
|
+
spec.email = ["peejfrias@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{A gem that provides information on the most common cat breeds}
|
|
13
|
+
spec.homepage = "https://github.com/ThePeej/cat-breeds-cli-gem"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
spec.executables << 'cat-breeds'
|
|
22
|
+
|
|
23
|
+
spec.require_paths = ["lib"]
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
28
|
+
spec.add_development_dependency "pry"
|
|
29
|
+
|
|
30
|
+
spec.add_dependency "nokogiri"
|
|
31
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class CatBreeds::Cat
|
|
2
|
+
attr_accessor :name, :page_url, :blurb, :fun_fact, :description, :history, :personality, :health, :grooming, :characteristics
|
|
3
|
+
|
|
4
|
+
@@all = []
|
|
5
|
+
|
|
6
|
+
def initialize(name, page_url)
|
|
7
|
+
@name = name
|
|
8
|
+
@page_url = page_url
|
|
9
|
+
self.class.all << self
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add_details(details) #takes hash returned from CatBreeds::Scraper.scrape_profile(url) and adds breed data to the corresponding instance of cat breed
|
|
13
|
+
details.each do |k,v|
|
|
14
|
+
self.send("#{k}=", v)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.all
|
|
19
|
+
@@all
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
class CatBreeds::CLI
|
|
2
|
+
|
|
3
|
+
BASE_PATH = "http://www.vetstreet.com"
|
|
4
|
+
|
|
5
|
+
def start
|
|
6
|
+
puts ""
|
|
7
|
+
puts "----------------------------------------"
|
|
8
|
+
puts " CAT BREEDS "
|
|
9
|
+
puts "----------------------------------------"
|
|
10
|
+
breeds = make_cats
|
|
11
|
+
list_cats(breeds)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def make_cats #Scrapes site index page to gather all of the breeds and breed urls
|
|
15
|
+
breeds_array = CatBreeds::Scraper.scrape_index(BASE_PATH + "/cats/breeds")
|
|
16
|
+
breeds_array.collect do |breed|
|
|
17
|
+
CatBreeds::Cat.new(breed[:name], breed[:page_url])
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def list_cats(breeds) #indexes through array of cat breeds returned from make_cats and lists each one for user to select from
|
|
22
|
+
puts ""
|
|
23
|
+
breeds.each.with_index(1) {|b,i|puts "[#{i}] #{b.name}"}
|
|
24
|
+
puts "type [exit] at any time to close"
|
|
25
|
+
puts ""
|
|
26
|
+
puts "Enter the cat breed or number that you would like to learn more about:"
|
|
27
|
+
input = gets.strip
|
|
28
|
+
if input.to_i > 0
|
|
29
|
+
view_breed_overview(CatBreeds::Cat.all[input.to_i - 1])
|
|
30
|
+
elsif CatBreeds::Cat.all.detect{|breed|breed.name.downcase == input.downcase}
|
|
31
|
+
view_breed_overview(CatBreeds::Cat.all.detect{|breed| breed.name.downcase == input.downcase})
|
|
32
|
+
elsif input.downcase == "exit"
|
|
33
|
+
self.goodbye
|
|
34
|
+
else
|
|
35
|
+
puts ""
|
|
36
|
+
puts "Invalid Input. Please try again."
|
|
37
|
+
self.list_cats(breeds)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def view_breed_overview(breed) #upon selecting a specific cat breed, this method scrapes that breed's url page for more information
|
|
42
|
+
details = CatBreeds::Scraper.scrape_profile(BASE_PATH + breed.page_url)
|
|
43
|
+
breed.add_details(details)
|
|
44
|
+
puts ""
|
|
45
|
+
puts "----------------------------------------"
|
|
46
|
+
puts "Overview of the #{breed.name}"
|
|
47
|
+
puts "----------------------------------------"
|
|
48
|
+
puts ""
|
|
49
|
+
puts "#{breed.blurb}"
|
|
50
|
+
puts ""
|
|
51
|
+
puts "Fun Fact!"
|
|
52
|
+
puts "#{breed.fun_fact}"
|
|
53
|
+
view_more_details(breed)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def view_more_details(breed) #after more info is scraped from view_breed_overview, more options are presented to learn more about breed
|
|
57
|
+
puts ""
|
|
58
|
+
puts "Learn more about the #{breed.name}:"
|
|
59
|
+
puts "[1] Description"
|
|
60
|
+
puts "[2] Characteristics"
|
|
61
|
+
puts "[3] History"
|
|
62
|
+
puts "[4] Personality"
|
|
63
|
+
puts "[5] Grooming"
|
|
64
|
+
puts "[6] Health"
|
|
65
|
+
puts "[Back] to list of all cat breeds"
|
|
66
|
+
input = gets.strip
|
|
67
|
+
topic = nil
|
|
68
|
+
info = nil
|
|
69
|
+
case input.downcase
|
|
70
|
+
when "1","description"
|
|
71
|
+
topic = "Description"
|
|
72
|
+
info = breed.description
|
|
73
|
+
when "2","characteristics"
|
|
74
|
+
topic = "Characteristics"
|
|
75
|
+
info = Proc.new{
|
|
76
|
+
i = 0
|
|
77
|
+
while i < breed.characteristics.length
|
|
78
|
+
puts "#{breed.characteristics[i][0]}: #{breed.characteristics[i][1]}"
|
|
79
|
+
i += 1
|
|
80
|
+
end
|
|
81
|
+
}
|
|
82
|
+
when "3","history"
|
|
83
|
+
topic = "History"
|
|
84
|
+
info = breed.history
|
|
85
|
+
when "4","personality"
|
|
86
|
+
topic = "Personality"
|
|
87
|
+
info = breed.personality
|
|
88
|
+
when "5","grooming"
|
|
89
|
+
topic = "Grooming"
|
|
90
|
+
info = breed.grooming
|
|
91
|
+
when "6","health"
|
|
92
|
+
topic = "Health"
|
|
93
|
+
info = breed.health
|
|
94
|
+
when "back"
|
|
95
|
+
start
|
|
96
|
+
when "exit"
|
|
97
|
+
goodbye
|
|
98
|
+
else
|
|
99
|
+
puts ""
|
|
100
|
+
puts "Invalid Input. Please try again."
|
|
101
|
+
view_more_details(breed)
|
|
102
|
+
end
|
|
103
|
+
view_topic(breed, topic, info)
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def view_topic(breed, topic, info) #once specific topic is selected, more information on that topic is presented to the user
|
|
108
|
+
puts ""
|
|
109
|
+
puts "----------------------------------------"
|
|
110
|
+
puts "#{breed.name} - #{topic}"
|
|
111
|
+
puts "----------------------------------------"
|
|
112
|
+
puts ""
|
|
113
|
+
if info.is_a?(String)
|
|
114
|
+
puts "#{info}"
|
|
115
|
+
else
|
|
116
|
+
info.call
|
|
117
|
+
end
|
|
118
|
+
puts ""
|
|
119
|
+
puts "[1] Learn more about the #{breed.name}"
|
|
120
|
+
puts "[2] Learn about a different cat breed"
|
|
121
|
+
input = gets.strip
|
|
122
|
+
case input.downcase
|
|
123
|
+
when "1"
|
|
124
|
+
view_more_details(breed)
|
|
125
|
+
when "2","personality"
|
|
126
|
+
start
|
|
127
|
+
when "exit"
|
|
128
|
+
goodbye
|
|
129
|
+
else
|
|
130
|
+
puts ""
|
|
131
|
+
puts "Invalid Input. Please try again."
|
|
132
|
+
view_topic(breed, topic, info)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def goodbye #upon exiting the program, the user is presented a thank you and cat artwork
|
|
137
|
+
puts ""
|
|
138
|
+
puts "Thanks for learning about cats!"
|
|
139
|
+
puts ""
|
|
140
|
+
puts " _ "
|
|
141
|
+
puts " \\`*-. "
|
|
142
|
+
puts " ) _`-. "
|
|
143
|
+
puts " . : `. . "
|
|
144
|
+
puts " : _ ' \\ "
|
|
145
|
+
puts " ; *` _. `*-._ "
|
|
146
|
+
puts " `-.-' `-. "
|
|
147
|
+
puts " ; ` `. "
|
|
148
|
+
puts " :. . \\ "
|
|
149
|
+
puts " . \\ . : .-' . "
|
|
150
|
+
puts " ' `+.; ; ' : "
|
|
151
|
+
puts " : ' | ; ;-. "
|
|
152
|
+
puts " ; ' : :`-: _.`* ;"
|
|
153
|
+
puts " [bye] .*' / .*' ; .*`- +' `*' "
|
|
154
|
+
puts " `*-* `*-* `*-*' "
|
|
155
|
+
puts ""
|
|
156
|
+
exit
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
class CatBreeds::Scraper
|
|
2
|
+
|
|
3
|
+
def self.scrape_index(url) #creates and returns an array of hashes which contain cat breeds and page urls
|
|
4
|
+
cat_breeds = []
|
|
5
|
+
doc = Nokogiri::HTML(open(url))
|
|
6
|
+
breeds = doc.css("#hub-breed-list-container ul li a")
|
|
7
|
+
breeds.each do |b|
|
|
8
|
+
breed = {}
|
|
9
|
+
breed[:name] = b.text
|
|
10
|
+
breed[:page_url] = b.attr("href")
|
|
11
|
+
cat_breeds << breed
|
|
12
|
+
end
|
|
13
|
+
cat_breeds
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.scrape_profile(url) #creates and returns a hash of a cat breed with more information for the user to view
|
|
17
|
+
breed = {}
|
|
18
|
+
doc = Nokogiri::HTML(open(url))
|
|
19
|
+
breed[:blurb] = doc.css("#breed-detail p").text.gsub("\n","").gsub("\t","").gsub("\r","").strip
|
|
20
|
+
breed[:fun_fact] = doc.css(".interesting-breed-fact p").text.gsub("\n","").gsub("\t","").gsub("\r","").strip
|
|
21
|
+
breed[:description] = doc.css("#overview .richtext p").text.gsub("\n","").gsub("\t","").gsub("\r","").gsub(" If the video doesn't start playing momentarily, please install the latest version of Flash.","").strip
|
|
22
|
+
breed[:history] = doc.css("#history .richtext p").text.gsub("\n","").gsub("\t","").gsub("\r","").strip
|
|
23
|
+
breed[:personality] = doc.css("#personality .richtext p").text.gsub("\n","").gsub("\t","").gsub("\r","").strip
|
|
24
|
+
breed[:health] = doc.css("#health .richtext p").text.gsub("\n","").gsub("\t","").gsub("\r","").strip
|
|
25
|
+
breed[:grooming] = doc.css("#grooming .richtext p").text.gsub("\n","").gsub("\t","").gsub("\r","").strip
|
|
26
|
+
breed[:characteristics] = scrape_characteristics(url)
|
|
27
|
+
breed
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.scrape_characteristics(url) #creates and returns a hash of breed characteristics to be used in self.scrape_profile
|
|
31
|
+
characteristics = {}
|
|
32
|
+
doc = Nokogiri::HTML(open(url))
|
|
33
|
+
|
|
34
|
+
keys = []
|
|
35
|
+
doc.css("td.title").each {|key| keys << key.text.scan(/\A(\w+\s?\w+)/)[0][0].gsub(" ","_")}
|
|
36
|
+
values = []
|
|
37
|
+
doc.css("td.rating").each{|value| values << value.text}
|
|
38
|
+
keys.each_with_index do |key,i|
|
|
39
|
+
characteristics[key.to_sym] = values[i]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
characteristics.sort_by{|k,v|k}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
end
|
data/lib/cat_breeds.rb
ADDED
data/spec.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Specifications for the CLI Assessment
|
|
2
|
+
|
|
3
|
+
Specs:
|
|
4
|
+
- [X] Have a CLI for interfacing with the application - CLI is initiated at gem start up. First shows user a list of 50 cat breeds, and user must select via a CLI which cat breed to learn more about. From there, the user continues to use the CLI to learn about more details of the selected cat breed.
|
|
5
|
+
|
|
6
|
+
- [X] Pull data from an external source - Data is pulled from the index page (http://www.vetstreet.com/cats/breeds), and then data is pulled from each individual page of each breed (i.e. http://www.vetstreet.com/cats/abyssinian)
|
|
7
|
+
|
|
8
|
+
- [X] Implement both list and detail views - List view is 50 cat breeds pulled from the index page (http://www.vetstreet.com/cats). Detail views display a brief overview and fun fact, and then allow for options of which specific topic to learn more about. These details are pulled from each breed page (i.e. http://www.vetstreet.com/cats/abyssinian)
|
metadata
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cat_breeds
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- PJ Frias
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-01-22 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: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.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
|
+
- !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:
|
|
84
|
+
email:
|
|
85
|
+
- peejfrias@gmail.com
|
|
86
|
+
executables:
|
|
87
|
+
- cat-breeds
|
|
88
|
+
extensions: []
|
|
89
|
+
extra_rdoc_files: []
|
|
90
|
+
files:
|
|
91
|
+
- ".gitignore"
|
|
92
|
+
- ".rspec"
|
|
93
|
+
- ".travis.yml"
|
|
94
|
+
- CODE_OF_CONDUCT.md
|
|
95
|
+
- Gemfile
|
|
96
|
+
- Gemfile.lock
|
|
97
|
+
- LICENSE.txt
|
|
98
|
+
- NOTES.md
|
|
99
|
+
- README.md
|
|
100
|
+
- Rakefile
|
|
101
|
+
- bin/cat-breeds
|
|
102
|
+
- bin/console
|
|
103
|
+
- bin/setup
|
|
104
|
+
- cat_breeds.gemspec
|
|
105
|
+
- lib/cat_breeds.rb
|
|
106
|
+
- lib/cat_breeds/cats.rb
|
|
107
|
+
- lib/cat_breeds/cli.rb
|
|
108
|
+
- lib/cat_breeds/scraper.rb
|
|
109
|
+
- lib/cat_breeds/version.rb
|
|
110
|
+
- spec.md
|
|
111
|
+
homepage: https://github.com/ThePeej/cat-breeds-cli-gem
|
|
112
|
+
licenses:
|
|
113
|
+
- MIT
|
|
114
|
+
metadata: {}
|
|
115
|
+
post_install_message:
|
|
116
|
+
rdoc_options: []
|
|
117
|
+
require_paths:
|
|
118
|
+
- lib
|
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ">="
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0'
|
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
|
+
requirements:
|
|
126
|
+
- - ">="
|
|
127
|
+
- !ruby/object:Gem::Version
|
|
128
|
+
version: '0'
|
|
129
|
+
requirements: []
|
|
130
|
+
rubyforge_project:
|
|
131
|
+
rubygems_version: 2.7.3
|
|
132
|
+
signing_key:
|
|
133
|
+
specification_version: 4
|
|
134
|
+
summary: A gem that provides information on the most common cat breeds
|
|
135
|
+
test_files: []
|