cats_to_adopt 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 +1 -0
- data/.rspec_status +12 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.txt +21 -0
- data/NOTES.md +26 -0
- data/README.md +28 -0
- data/Rakefile +6 -0
- data/bin/cats_to_adopt +5 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cats_to_adopt.gemspec +42 -0
- data/fixtures/vcr_cassettes/cats_to_adopt.yml +3298 -0
- data/lib/cats_to_adopt.rb +9 -0
- data/lib/cats_to_adopt/CLI.rb +57 -0
- data/lib/cats_to_adopt/cat.rb +46 -0
- data/lib/cats_to_adopt/scraper.rb +30 -0
- data/lib/cats_to_adopt/version.rb +3 -0
- data/spec.md +14 -0
- metadata +165 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
class CatsToAdopt::CLI
|
2
|
+
|
3
|
+
BASE_PATH = "https://la.bestfriends.org/get-involved/adopt/"
|
4
|
+
|
5
|
+
def call
|
6
|
+
intro_message
|
7
|
+
make_cats
|
8
|
+
list_cats
|
9
|
+
menu
|
10
|
+
goodbye
|
11
|
+
end
|
12
|
+
|
13
|
+
def intro_message
|
14
|
+
puts "\n-----------------------------"
|
15
|
+
puts "| Welcome to Cats to Adopt! |"
|
16
|
+
puts "-----------------------------\n\n"
|
17
|
+
puts "Retrieving cat info..."
|
18
|
+
end
|
19
|
+
|
20
|
+
def make_cats
|
21
|
+
CatsToAdopt::Scraper.scrape_main_page(BASE_PATH + 'pets?field_animal_species_tid_selective=958')
|
22
|
+
end
|
23
|
+
|
24
|
+
def list_cats
|
25
|
+
CatsToAdopt::Cat.print_cats
|
26
|
+
end
|
27
|
+
|
28
|
+
def menu
|
29
|
+
input = ""
|
30
|
+
|
31
|
+
while input != "exit"
|
32
|
+
puts "\nEnter the number of the cat you would like more info on."
|
33
|
+
puts "Type list to list all cats or exit to exit the program."
|
34
|
+
input = gets.strip
|
35
|
+
|
36
|
+
cats = CatsToAdopt::Cat.all
|
37
|
+
|
38
|
+
if input.to_i > 0 && input.to_i < cats.size + 1
|
39
|
+
cat_in_question = cats[input.to_i - 1]
|
40
|
+
attributes = CatsToAdopt::Scraper.scrape_profile_page(BASE_PATH + 'pet/' + cat_in_question.id)
|
41
|
+
cat_in_question.add_cat_attributes(attributes)
|
42
|
+
cat_in_question.print_cat_info
|
43
|
+
elsif input == "list"
|
44
|
+
list_cats
|
45
|
+
elsif input == "exit"
|
46
|
+
puts "\nClosing program ..."
|
47
|
+
else
|
48
|
+
puts "Please enter the number of a cat, list, or exit."
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def goodbye
|
53
|
+
puts "\nGoodbye!"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end # end CLI class
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class CatsToAdopt::Cat
|
2
|
+
attr_accessor :name, :gender, :size, :location, :profile_url, :id, :age, :color, :weight
|
3
|
+
|
4
|
+
@@all = []
|
5
|
+
|
6
|
+
# INSTANCE METHODS
|
7
|
+
# save a cat when it's created
|
8
|
+
def initialize
|
9
|
+
@@all << self
|
10
|
+
end
|
11
|
+
|
12
|
+
# set additional attributes on a cat
|
13
|
+
def add_cat_attributes(attributes)
|
14
|
+
self.color = attributes[:color]
|
15
|
+
self.weight = attributes[:weight]
|
16
|
+
self.age = attributes[:age]
|
17
|
+
self.profile_url = 'https://la.bestfriends.org/get-involved/adopt/pet/' + self.id
|
18
|
+
end
|
19
|
+
|
20
|
+
# prints detailed information for a cat
|
21
|
+
def print_cat_info
|
22
|
+
puts "\nCat Name: #{self.name}"
|
23
|
+
puts "-- ID: #{self.id}"
|
24
|
+
puts "-- Gender: #{self.gender}"
|
25
|
+
puts "-- Age: #{self.age}"
|
26
|
+
puts "-- Color: #{self.color}"
|
27
|
+
puts "-- Size: #{self.size}"
|
28
|
+
puts "-- Weight: #{self.weight}"
|
29
|
+
puts "-- Location: #{self.location}"
|
30
|
+
puts "-- Profile Link: #{self.profile_url}\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
# CLASS METHODS
|
34
|
+
def self.all
|
35
|
+
@@all
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.print_cats
|
39
|
+
puts "\nCats available now:"
|
40
|
+
|
41
|
+
self.all.each.with_index(1) do |cat, i|
|
42
|
+
puts "#{i}. #{cat.name} - #{cat.gender} - #{cat.size}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end # end Cat class
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class CatsToAdopt::Scraper
|
2
|
+
|
3
|
+
# for each cat on the main page, scrapes the page for the cat's data and
|
4
|
+
# instantiates a Cat object with that data.
|
5
|
+
def self.scrape_main_page(main_page_url)
|
6
|
+
main_page = Nokogiri::HTML(open(main_page_url))
|
7
|
+
|
8
|
+
main_page.search(".pet-list-item").each do |cat|
|
9
|
+
new_cat = CatsToAdopt::Cat.new
|
10
|
+
new_cat.name = cat.search(".views-field-field-animal-name").text.strip
|
11
|
+
new_cat.id = cat.search(".views-field-field-animal-name a").attr("href").text.gsub("/get-involved/adopt/pet/", "").strip
|
12
|
+
new_cat.gender = cat.search(".views-field-field-animal-sex .field-content").text.strip
|
13
|
+
new_cat.size = cat.search(".views-field-field-animal-size .field-content").text.strip
|
14
|
+
new_cat.location = cat.search(".views-field-field-shelter-state .field-content").text.strip
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# given a cat's profile page URL, scrapes the cat's profile page and returns a
|
19
|
+
# hash of additional attributes for that cat
|
20
|
+
def self.scrape_profile_page(profile_url)
|
21
|
+
profile_page = Nokogiri::HTML(open(profile_url))
|
22
|
+
attributes = {}
|
23
|
+
|
24
|
+
attributes[:color] = profile_page.search(".petpoint-pet-color .info").text.strip
|
25
|
+
attributes[:weight] = profile_page.search(".card__info .petpoint-pet-weight:nth-child(7) .info").text.strip
|
26
|
+
attributes[:age] = profile_page.search(".card__info .petpoint-pet-age:nth-child(4) .info").text.strip
|
27
|
+
|
28
|
+
attributes
|
29
|
+
end
|
30
|
+
end # end Scraper class
|
data/spec.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Specifications for the CLI Assessment
|
2
|
+
|
3
|
+
Specs:
|
4
|
+
- [X] Have a CLI for interfacing with the application
|
5
|
+
|
6
|
+
The CLI shows a list of current cats available for adoption at the NKLA website. It asks the user which cat they would like more info on and also allows them to list the cats again or exit the program. The CLI validates the user input.
|
7
|
+
|
8
|
+
- [X] Pull data from an external source
|
9
|
+
|
10
|
+
I used Nokogiri & Open URI to scrape data from the NKLA index site for adoptable cats as well as each cat's profile page. I used VCR and WebMock to cache the results of my HTTP requests during testing as to not bombard the NKLA site with requests. The CLI scrapes the index page when the program starts, but each cat's profile page is only scraped when that cat's info is requested by the user to reduce the initial loading time.
|
11
|
+
|
12
|
+
- [X] Implement both list and detail views
|
13
|
+
|
14
|
+
The user selects a cat number which then shows them additional information about the cat scraped from the cat's profile page.
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cats_to_adopt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Allyson Wesman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-25 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: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: nokogiri
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Created as Ruby final project for Flatiron School's Online Web Developer
|
112
|
+
pgoram. The gem scrapes No Kill LA's page on cats available to adopt now and lists
|
113
|
+
them in a CLI interface. The user can choose a cat to get more information.
|
114
|
+
email:
|
115
|
+
- allysonwesman@gmail.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec_status"
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- LICENSE.txt
|
126
|
+
- NOTES.md
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/cats_to_adopt
|
130
|
+
- bin/console
|
131
|
+
- bin/setup
|
132
|
+
- cats_to_adopt.gemspec
|
133
|
+
- fixtures/vcr_cassettes/cats_to_adopt.yml
|
134
|
+
- lib/cats_to_adopt.rb
|
135
|
+
- lib/cats_to_adopt/CLI.rb
|
136
|
+
- lib/cats_to_adopt/cat.rb
|
137
|
+
- lib/cats_to_adopt/scraper.rb
|
138
|
+
- lib/cats_to_adopt/version.rb
|
139
|
+
- spec.md
|
140
|
+
homepage: https://github.com/allysonw/cats-to-adopt-cli-gem
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata:
|
144
|
+
allowed_push_host: https://rubygems.org/
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 2.7.4
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: Lists and provides info on current cats available to adopt from NKLA's website.
|
165
|
+
test_files: []
|