dog_breeds 0.2.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 +7 -0
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +21 -0
- data/README.md +31 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/dog-breeds +7 -0
- data/bin/setup +8 -0
- data/dog_breeds.gemspec +29 -0
- data/lib/dog_breeds/cli.rb +185 -0
- data/lib/dog_breeds/dog.rb +21 -0
- data/lib/dog_breeds/scraper.rb +48 -0
- data/lib/dog_breeds/version.rb +3 -0
- data/lib/dog_breeds.rb +11 -0
- data/spec.md +11 -0
- metadata +133 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: dca218a34b11a76edcec823dba2b758227bad9fd05b3fc0bb754c6d59de4e021
|
|
4
|
+
data.tar.gz: 70742cd22fbc0a0f2560e5aeeabd7ae712c410f80b432400b71a29415bfbc75e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e81557475820e1ae619f450d0ca5f8122215e9206566b2c0e59fdfe04b007e338a3dfe9c119192b6fa7f53a834962cf7afb2f8d3cc8c4754c34239637e3a25ac
|
|
7
|
+
data.tar.gz: 6befd72d26bf6fd5fc34988f6abadaa0289c72fd7fd002a272930897b9b7e7d4cb598cb9a85ff7506da8a443c58690f693961e08994cd377e04fbd214563d945
|
data/.gitignore
ADDED
data/.rspec
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 'freddymorato@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
|
+
dog_breeds (0.2.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.2)
|
|
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.4.2)
|
|
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.1)
|
|
33
|
+
|
|
34
|
+
PLATFORMS
|
|
35
|
+
ruby
|
|
36
|
+
|
|
37
|
+
DEPENDENCIES
|
|
38
|
+
bundler (~> 1.16)
|
|
39
|
+
dog_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 'Frederico Morato'
|
|
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,31 @@
|
|
|
1
|
+
# Dog Breeds
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
$ gem install dog_breeds
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
Type the command below to start the dog_breeds CLI and start learning about dog breeds!
|
|
10
|
+
|
|
11
|
+
$ dog-breeds
|
|
12
|
+
|
|
13
|
+
User can select a dog from the main menu by entering either its breed name or menu number. Once you've selected a dog 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 dog breed, or you can go back to the home menu and learn about a different dog breed. Enter exit at any point while using dog_breeds to close out of the gem CLI.
|
|
14
|
+
|
|
15
|
+
## Development
|
|
16
|
+
|
|
17
|
+
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.
|
|
18
|
+
|
|
19
|
+
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).
|
|
20
|
+
|
|
21
|
+
## Contributing
|
|
22
|
+
|
|
23
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/'Freddymorato'/dog_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.
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
28
|
+
|
|
29
|
+
## Code of Conduct
|
|
30
|
+
|
|
31
|
+
Everyone interacting in the DogBreeds project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/'Freddymorato'/dog_breeds/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 "dog_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/dog-breeds
ADDED
data/bin/setup
ADDED
data/dog_breeds.gemspec
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "dog_breeds/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "dog_breeds"
|
|
8
|
+
spec.version = DogBreeds::VERSION
|
|
9
|
+
spec.authors = ["'Frederico Morato'"]
|
|
10
|
+
spec.email = ["'freddymorato@gmail.com'"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{A gem that provides information on different dog breeds}
|
|
13
|
+
spec.homepage = "https://github.com/Freddymorato/dog-breeds-cli-gem"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
spec.executables << 'dog-breeds'
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
26
|
+
spec.add_development_dependency "pry"
|
|
27
|
+
|
|
28
|
+
spec.add_dependency "nokogiri"
|
|
29
|
+
end
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
class DogBreeds::CLI
|
|
2
|
+
|
|
3
|
+
BASE_PATH = "http://dogtime.com"
|
|
4
|
+
|
|
5
|
+
def call
|
|
6
|
+
puts ""
|
|
7
|
+
puts "*|*----------------------------------------*|*"
|
|
8
|
+
puts " *** DOG BREEDS *** "
|
|
9
|
+
puts "*|*----------------------------------------*|*"
|
|
10
|
+
breeds = make_dogs
|
|
11
|
+
@i = 0
|
|
12
|
+
@j = 9
|
|
13
|
+
list_dogs(breeds)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def make_dogs #Scrapes site index page to gather all of the breeds and breed urls
|
|
17
|
+
breeds_array = DogBreeds::Scraper.scrape_index(BASE_PATH + "/dog-breeds/profiles")
|
|
18
|
+
breeds_array.collect do |breed|
|
|
19
|
+
DogBreeds::Dog.new(breed[:name], breed[:page_url])
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def list_dogs(breeds) #indexes through array of dog breeds returned from make_dogs and lists each one for user to select from
|
|
24
|
+
puts ""
|
|
25
|
+
breeds[@i..@i+@j].each.with_index(@i + 1) {|b,i|puts "[#{i}] #{b.name}"}
|
|
26
|
+
puts "[all]" if @j != 209
|
|
27
|
+
puts "[less]" if @j == 209
|
|
28
|
+
puts "[next]" if @i == 0 && @j == 9
|
|
29
|
+
puts "[back||next]" if @i >= 10 && @i+@j < 209
|
|
30
|
+
puts "[back]" if @i+@j >= 209 && @j == 9
|
|
31
|
+
puts ""
|
|
32
|
+
puts "type [exit] at any time to close"
|
|
33
|
+
puts ""
|
|
34
|
+
puts "Enter the dog breed or number that you would like to learn more about:"
|
|
35
|
+
input = gets.strip
|
|
36
|
+
if input.to_i > 0 && input.to_i <= breeds.length
|
|
37
|
+
view_breed_overview(DogBreeds::Dog.all[input.to_i - 1])
|
|
38
|
+
elsif DogBreeds::Dog.all.detect{|breed|breed.name.downcase == input.downcase}
|
|
39
|
+
view_breed_overview(DogBreeds::Dog.all.detect{|breed| breed.name.downcase == input.downcase})
|
|
40
|
+
elsif input.downcase == "all"
|
|
41
|
+
@i = 0
|
|
42
|
+
@j = 209
|
|
43
|
+
list_dogs(breeds)
|
|
44
|
+
elsif input.downcase == "less"
|
|
45
|
+
@i = 0
|
|
46
|
+
@j = 9
|
|
47
|
+
list_dogs(breeds)
|
|
48
|
+
elsif input.downcase == "next" && @i+@j == 209
|
|
49
|
+
puts ""
|
|
50
|
+
puts "That's all the dog breeds!"
|
|
51
|
+
list_dogs(breeds)
|
|
52
|
+
elsif input.downcase == "next"
|
|
53
|
+
@i += 10
|
|
54
|
+
list_dogs(breeds)
|
|
55
|
+
elsif input.downcase == "back" && @i == 0
|
|
56
|
+
puts ""
|
|
57
|
+
puts "That's all the dog breeds!"
|
|
58
|
+
list_dogs(breeds)
|
|
59
|
+
elsif input.downcase == "back"
|
|
60
|
+
@i -= 10
|
|
61
|
+
list_dogs(breeds)
|
|
62
|
+
elsif input.downcase == "exit"
|
|
63
|
+
self.goodbye
|
|
64
|
+
else
|
|
65
|
+
puts ""
|
|
66
|
+
puts "Invalid Input. Please try again."
|
|
67
|
+
self.list_dogs(breeds)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def view_breed_overview(breed) #upon selecting a specific dog breed, this method scrapes that breed's url page for more information
|
|
72
|
+
details = DogBreeds::Scraper.scrape_profile(breed.page_url)
|
|
73
|
+
breed.add_details(details)
|
|
74
|
+
puts ""
|
|
75
|
+
puts "*|*-------------------------------------------------------------------*|*"
|
|
76
|
+
puts " #{breed.name} "
|
|
77
|
+
puts "*|*-------------------------------------------------------------------*|*"
|
|
78
|
+
puts ""
|
|
79
|
+
puts "#{breed.intro}"
|
|
80
|
+
puts ""
|
|
81
|
+
puts "Size: #{breed.size}"
|
|
82
|
+
puts ""
|
|
83
|
+
view_more_details(breed)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def view_more_details(breed) #after more info is scraped from view_breed_overview, more options are presented to learn more about breed
|
|
87
|
+
puts ""
|
|
88
|
+
puts "Learn more about the #{breed.name}:"
|
|
89
|
+
puts "[1] Highlights"
|
|
90
|
+
puts "[2] History"
|
|
91
|
+
puts "[3] Personality"
|
|
92
|
+
puts "[4] Care"
|
|
93
|
+
puts "[5] Feeding"
|
|
94
|
+
puts "[6] Children And Other Pets"
|
|
95
|
+
puts "[Back] to list of all dog breeds"
|
|
96
|
+
input = gets.strip
|
|
97
|
+
topic = nil
|
|
98
|
+
info = nil
|
|
99
|
+
case input.downcase
|
|
100
|
+
when "1","highlights"
|
|
101
|
+
topic = "Highlights"
|
|
102
|
+
info = breed.highlights
|
|
103
|
+
when "2","history"
|
|
104
|
+
topic = "History"
|
|
105
|
+
info = breed.history
|
|
106
|
+
when "3","personality"
|
|
107
|
+
topic = "Personality"
|
|
108
|
+
info = breed.personality
|
|
109
|
+
when "4","care"
|
|
110
|
+
topic = "Care"
|
|
111
|
+
info = breed.care
|
|
112
|
+
when "5","feeding"
|
|
113
|
+
topic = "Feeding"
|
|
114
|
+
info = breed.feeding
|
|
115
|
+
when "6","children and other pets"
|
|
116
|
+
topic = "Children And Other Pets"
|
|
117
|
+
info = breed.children_and_other_pets
|
|
118
|
+
when "back"
|
|
119
|
+
call
|
|
120
|
+
when "exit"
|
|
121
|
+
goodbye
|
|
122
|
+
else
|
|
123
|
+
puts ""
|
|
124
|
+
puts "Invalid Input. Please try again."
|
|
125
|
+
view_more_details(breed)
|
|
126
|
+
end
|
|
127
|
+
view_topic(breed, topic, info)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def view_topic(breed, topic, info) #once specific topic is selected, more information on that topic is presented to the user
|
|
131
|
+
puts ""
|
|
132
|
+
puts "*|*-------------------------------------------------------------------*|*"
|
|
133
|
+
puts " #{breed.name} - #{topic} "
|
|
134
|
+
puts "*|*-------------------------------------------------------------------*|*"
|
|
135
|
+
puts ""
|
|
136
|
+
if info.is_a?(String)
|
|
137
|
+
puts "#{info}"
|
|
138
|
+
else
|
|
139
|
+
puts "Sorry, there's no info for #{breed.name} on this topic. Please try again."
|
|
140
|
+
view_more_details(breed)
|
|
141
|
+
end
|
|
142
|
+
puts ""
|
|
143
|
+
puts "[1] Learn more about the #{breed.name}"
|
|
144
|
+
puts "[2] Learn about a different dog breed"
|
|
145
|
+
input = gets.strip
|
|
146
|
+
case input.downcase
|
|
147
|
+
when "1"
|
|
148
|
+
view_more_details(breed)
|
|
149
|
+
when "2"
|
|
150
|
+
call
|
|
151
|
+
when "exit"
|
|
152
|
+
goodbye
|
|
153
|
+
else
|
|
154
|
+
puts ""
|
|
155
|
+
puts "Invalid Input. Please try again."
|
|
156
|
+
view_topic(breed, topic, info)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def goodbye #upon exiting the program, the user is presented a thank you and dog artwork
|
|
161
|
+
puts ""
|
|
162
|
+
puts "*|*----------------------------------------*|*"
|
|
163
|
+
puts " Thanks for learning about dogs! "
|
|
164
|
+
puts "*|*----------------------------------------*|*"
|
|
165
|
+
puts ""
|
|
166
|
+
puts " "
|
|
167
|
+
puts " ,-~~~~-, "
|
|
168
|
+
puts " .-~~~; ;~~~-. "
|
|
169
|
+
puts " / / \ \ "
|
|
170
|
+
puts "{ .'{ O O }'. } "
|
|
171
|
+
puts " `~` { .-~~~~-. } `~` "
|
|
172
|
+
puts " ;/ \; "
|
|
173
|
+
puts " /'._ () _.'\ "
|
|
174
|
+
puts " / `~~~~` \ "
|
|
175
|
+
puts " ; ; "
|
|
176
|
+
puts " { } "
|
|
177
|
+
puts " { } { } "
|
|
178
|
+
puts " { } { } "
|
|
179
|
+
puts " / \ / \ "
|
|
180
|
+
puts " { { { }~~{ } } } "
|
|
181
|
+
puts " `~~~~~` `~~~~~` "
|
|
182
|
+
puts ""
|
|
183
|
+
exit
|
|
184
|
+
end
|
|
185
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class DogBreeds::Dog
|
|
2
|
+
attr_accessor :name, :page_url, :intro, :highlights, :history, :personality, :size, :care, :feeding, :children_and_other_pets
|
|
3
|
+
|
|
4
|
+
@@all = []
|
|
5
|
+
|
|
6
|
+
def initialize(name, page_url)
|
|
7
|
+
@name = name
|
|
8
|
+
@page_url = page_url
|
|
9
|
+
@@all << self
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add_details(details) #takes hash returned from DogBreeds::Scraper.scrape_profile(url) and adds breed data to the corresponding instance of dog 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
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
class DogBreeds::Scraper
|
|
2
|
+
|
|
3
|
+
def self.scrape_index(url) #creates and returns an array of hashes which contain dog breeds and page urls
|
|
4
|
+
dog_breeds = []
|
|
5
|
+
doc = Nokogiri::HTML(open(url))
|
|
6
|
+
breeds = doc.css(".group-list-item .post-title")
|
|
7
|
+
|
|
8
|
+
breeds.each do |b|
|
|
9
|
+
breed = {}
|
|
10
|
+
breed[:name] = b.text
|
|
11
|
+
breed[:page_url] = b.attr("href")
|
|
12
|
+
dog_breeds << breed
|
|
13
|
+
end
|
|
14
|
+
dog_breeds
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.scrape_profile(url) #creates and returns a hash of a dog breed with more information for the user to view
|
|
18
|
+
doc = Nokogiri::HTML(open(url))
|
|
19
|
+
attributes = {}
|
|
20
|
+
|
|
21
|
+
y = doc.css("header p")
|
|
22
|
+
y.each do |x|
|
|
23
|
+
attributes[:intro] = x.text if x.text.include? "dog breed"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
list = doc.css(".breed-data-item.js-accordion-item.item-expandable-content")
|
|
27
|
+
list.each do |i|
|
|
28
|
+
if i.css("h2").text.include? "Highlights"
|
|
29
|
+
attributes[:highlights] = i.css("div").text.gsub("\n","").gsub("\t","").gsub("\r","").gsub("\"","")
|
|
30
|
+
elsif i.css("h2").text.include? "History"
|
|
31
|
+
attributes[:history] = i.css("div").text.gsub("\n","").gsub("\t","").gsub("\r","").gsub("\"","")
|
|
32
|
+
elsif i.css("h2").text.include? "Size"
|
|
33
|
+
attributes[:size] = i.css(".breed-data-item-content.js-breed-data-section").text.gsub("\n","").gsub("\t","").gsub("\r","").gsub("\"","")
|
|
34
|
+
elsif i.css("h2").text.include? "Personality"
|
|
35
|
+
attributes[:personality] = i.css("div").text.gsub("\n","").gsub("\t","").gsub("\r","").gsub("\"","")
|
|
36
|
+
elsif i.css("h2").text.include? "Care"
|
|
37
|
+
attributes[:care] = i.css("div").text.gsub("\n","").gsub("\t","").gsub("\r","").gsub("\"","")
|
|
38
|
+
elsif i.css("h2").text.include? "Feeding"
|
|
39
|
+
attributes[:feeding] = i.css(".breed-data-item-content.js-breed-data-section").text.gsub("\n","").gsub("\t","").gsub("\r","").gsub("\"","")
|
|
40
|
+
elsif i.css("h2").text.include? "Children And Other Pets"
|
|
41
|
+
attributes[:children_and_other_pets] = i.css("div").text.gsub("\n","").gsub("\t","").gsub("\r","").gsub("\"","")
|
|
42
|
+
else
|
|
43
|
+
nil
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
attributes
|
|
47
|
+
end
|
|
48
|
+
end
|
data/lib/dog_breeds.rb
ADDED
data/spec.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Specifications for the CLI Assessment
|
|
2
|
+
|
|
3
|
+
Specs:
|
|
4
|
+
- [X] Have a CLI for interfacing with the application
|
|
5
|
+
- CLI is launched at gem start up. First it displays to the user a list of 209 dog breeds, and the user must select a dog breed to learn more about via a CLI. From that point on, the user continues to use the CLI to learn about more details on the selected dog breed.
|
|
6
|
+
|
|
7
|
+
- [X] Pull data from an external source
|
|
8
|
+
- The data is scraped from the index page (http://www.dogtime.com), and then some more is scraped from each individual page of each breed.
|
|
9
|
+
|
|
10
|
+
- [X] Implement both list and detail views
|
|
11
|
+
- List view contains 209 dog breeds scraped from the index page (http://www.dogtime.com). Detail views display a brief overview of a specific breed, and then allow for options of which specific topic to learn more about. These details are scraped from each breed page.
|
metadata
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dog_breeds
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- "'Frederico Morato'"
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-04-11 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
|
+
- "'freddymorato@gmail.com'"
|
|
86
|
+
executables:
|
|
87
|
+
- dog-breeds
|
|
88
|
+
extensions: []
|
|
89
|
+
extra_rdoc_files: []
|
|
90
|
+
files:
|
|
91
|
+
- ".gitignore"
|
|
92
|
+
- ".rspec"
|
|
93
|
+
- CODE_OF_CONDUCT.md
|
|
94
|
+
- Gemfile
|
|
95
|
+
- Gemfile.lock
|
|
96
|
+
- LICENSE.txt
|
|
97
|
+
- README.md
|
|
98
|
+
- Rakefile
|
|
99
|
+
- bin/console
|
|
100
|
+
- bin/dog-breeds
|
|
101
|
+
- bin/setup
|
|
102
|
+
- dog_breeds.gemspec
|
|
103
|
+
- lib/dog_breeds.rb
|
|
104
|
+
- lib/dog_breeds/cli.rb
|
|
105
|
+
- lib/dog_breeds/dog.rb
|
|
106
|
+
- lib/dog_breeds/scraper.rb
|
|
107
|
+
- lib/dog_breeds/version.rb
|
|
108
|
+
- spec.md
|
|
109
|
+
homepage: https://github.com/Freddymorato/dog-breeds-cli-gem
|
|
110
|
+
licenses:
|
|
111
|
+
- MIT
|
|
112
|
+
metadata: {}
|
|
113
|
+
post_install_message:
|
|
114
|
+
rdoc_options: []
|
|
115
|
+
require_paths:
|
|
116
|
+
- lib
|
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
|
+
requirements:
|
|
119
|
+
- - ">="
|
|
120
|
+
- !ruby/object:Gem::Version
|
|
121
|
+
version: '0'
|
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
|
+
requirements:
|
|
124
|
+
- - ">="
|
|
125
|
+
- !ruby/object:Gem::Version
|
|
126
|
+
version: '0'
|
|
127
|
+
requirements: []
|
|
128
|
+
rubyforge_project:
|
|
129
|
+
rubygems_version: 2.7.6
|
|
130
|
+
signing_key:
|
|
131
|
+
specification_version: 4
|
|
132
|
+
summary: A gem that provides information on different dog breeds
|
|
133
|
+
test_files: []
|