blue_cross_pets 0.0.4 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blue_cross_pets.rb +0 -4
- data/lib/blue_cross_pets/cat.rb +3 -40
- data/lib/blue_cross_pets/cli.rb +45 -7
- data/lib/blue_cross_pets/dog.rb +6 -39
- data/lib/blue_cross_pets/pet.rb +7 -0
- data/lib/blue_cross_pets/scraper.rb +6 -13
- data/lib/blue_cross_pets/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23822b1062b0a6f43f623f970a9186bd17caca3461efb57760935d65ad0d983a
|
4
|
+
data.tar.gz: 24602f0003f6480ba21a3d0329942053e6952755b1bf1b76f82d37454f01be3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14a589f90250e6e72f38c5c3c42e05197ef08c29454f7ae0faab9effdff249baba6f58bb9e45814e24d09b94335bfe0f55b63a983108247c30ee1f9abd5e46f6
|
7
|
+
data.tar.gz: d230a672142366197031077b2c3abb470aec687a50629dafdff1b58816c46d184715ffea794979098488d230253656c2ec76fb0cb73bd9cb952752d5f28b0900
|
data/lib/blue_cross_pets.rb
CHANGED
data/lib/blue_cross_pets/cat.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative "./pet"
|
1
|
+
#require_relative "./pet"
|
2
2
|
|
3
3
|
class BlueCrossPets::Cat < BlueCrossPets::Pet
|
4
4
|
|
@@ -16,48 +16,11 @@ class BlueCrossPets::Cat < BlueCrossPets::Pet
|
|
16
16
|
@@cats
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.
|
20
|
-
self.all.each_with_index do |cat, index|
|
21
|
-
puts "#{index + 1}. ".blue + "#{cat.name} - #{cat.breed} - #{cat.gender} - #{cat.age} - #{cat.availability}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.scrape_cats
|
26
|
-
|
19
|
+
def self.create_cats
|
27
20
|
if all.length == 0
|
28
|
-
cat_array = BlueCrossPets::Scraper.scrape_index("https://www.bluecross.org.uk/rehome/cat")
|
21
|
+
cat_array = BlueCrossPets::Scraper.new.scrape_index("https://www.bluecross.org.uk/rehome/cat")
|
29
22
|
create_from_index(cat_array)
|
30
|
-
list_all
|
31
|
-
elsif all.length > 0
|
32
|
-
list_all
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.get_more_info(input)
|
38
|
-
|
39
|
-
index = input.to_i - 1
|
40
|
-
cat = all[index]
|
41
|
-
|
42
|
-
if !cat.reference
|
43
|
-
attribute_hash = BlueCrossPets::Scraper.scrape_profile(cat.profile_url)
|
44
|
-
cat.add_attributes(attribute_hash)
|
45
|
-
elsif cat.reference
|
46
23
|
end
|
47
|
-
|
48
|
-
puts "----------------------------- All about #{cat.name} -----------------------------".blue
|
49
|
-
puts "Age: ".light_white + "#{cat.age}"
|
50
|
-
puts "Gender: ".light_white + "#{cat.gender}"
|
51
|
-
puts "Availability: ".light_white + "#{cat.availability}"
|
52
|
-
puts "Breed & colour: ".light_white + "#{cat.breed_and_colour}"
|
53
|
-
|
54
|
-
if cat.can_live_with
|
55
|
-
puts "Can live with: ".light_white + "#{cat.can_live_with}"
|
56
|
-
end
|
57
|
-
|
58
|
-
puts "Bio: ".light_white + "#{cat.bio}"
|
59
|
-
puts "Animal reference number: ".light_white + "#{cat.reference}"
|
60
|
-
puts "Visit my page: ".light_white + "#{cat.profile_url}"
|
61
24
|
end
|
62
25
|
|
63
26
|
end
|
data/lib/blue_cross_pets/cli.rb
CHANGED
@@ -17,12 +17,14 @@ class BlueCrossPets::CLI
|
|
17
17
|
when "dogs"
|
18
18
|
@current_animal = "dog"
|
19
19
|
puts "----------------------------- Our dogs: -----------------------------".blue
|
20
|
-
BlueCrossPets::Dog.
|
20
|
+
BlueCrossPets::Dog.create_dogs
|
21
|
+
list_all
|
21
22
|
choose_animal
|
22
23
|
when "cats"
|
23
24
|
@current_animal = "cat"
|
24
25
|
puts "----------------------------- Our cats: -----------------------------".blue
|
25
|
-
BlueCrossPets::Cat.
|
26
|
+
BlueCrossPets::Cat.create_cats
|
27
|
+
list_all
|
26
28
|
choose_animal
|
27
29
|
when "exit"
|
28
30
|
else
|
@@ -31,6 +33,19 @@ class BlueCrossPets::CLI
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
36
|
+
def list_all
|
37
|
+
if @current_animal == "dog"
|
38
|
+
BlueCrossPets::Dog.all.each.with_index(1) do |dog, index|
|
39
|
+
puts "#{index}. ".blue + "#{dog.name} - #{dog.breed} - #{dog.gender} - #{dog.age} - #{dog.availability}"
|
40
|
+
end
|
41
|
+
|
42
|
+
elsif @current_animal == "cat"
|
43
|
+
BlueCrossPets::Cat.all.each.with_index(1) do |dog, index|
|
44
|
+
puts "#{index}. ".blue + "#{dog.name} - #{dog.breed} - #{dog.gender} - #{dog.age} - #{dog.availability}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
34
49
|
def number?(input)
|
35
50
|
input = input.to_s unless input.is_a? String
|
36
51
|
!!(/\A[+-]?\d+\z/.match(input))
|
@@ -41,12 +56,9 @@ class BlueCrossPets::CLI
|
|
41
56
|
input = gets.strip.downcase
|
42
57
|
|
43
58
|
if number?(input) == true
|
44
|
-
if @current_animal == "dog" && input.to_i.between?(1, BlueCrossPets::Dog.all.length)
|
45
|
-
puts "Paw-fect choice!".light_white
|
46
|
-
BlueCrossPets::Dog.get_more_info(input)
|
47
|
-
elsif @current_animal == "cat" && input.to_i.between?(1, BlueCrossPets::Cat.all.length)
|
59
|
+
if @current_animal == "dog" && input.to_i.between?(1, BlueCrossPets::Dog.all.length) || @current_animal == "cat" && input.to_i.between?(1, BlueCrossPets::Cat.all.length)
|
48
60
|
puts "Paw-fect choice!".light_white
|
49
|
-
|
61
|
+
list_additional_info(input)
|
50
62
|
else
|
51
63
|
puts "Sorry, we didn't understand that!".red
|
52
64
|
end
|
@@ -63,6 +75,32 @@ class BlueCrossPets::CLI
|
|
63
75
|
end
|
64
76
|
end
|
65
77
|
|
78
|
+
def list_additional_info(input)
|
79
|
+
index = input.to_i - 1
|
80
|
+
|
81
|
+
if @current_animal == "dog" && input.to_i.between?(1, BlueCrossPets::Dog.all.length)
|
82
|
+
pet_choice = BlueCrossPets::Dog.all[index]
|
83
|
+
elsif @current_animal == "cat" && input.to_i.between?(1, BlueCrossPets::Cat.all.length)
|
84
|
+
pet_choice = BlueCrossPets::Cat.all[index]
|
85
|
+
end
|
86
|
+
|
87
|
+
pet_choice.get_more_info
|
88
|
+
|
89
|
+
puts "----------------------------- All about #{pet_choice.name} -----------------------------".blue
|
90
|
+
puts "Age: ".light_white + "#{pet_choice.age}"
|
91
|
+
puts "Gender: ".light_white + "#{pet_choice.gender}"
|
92
|
+
puts "Availability: ".light_white + "#{pet_choice.availability}"
|
93
|
+
puts "Breed & colour: ".light_white + "#{pet_choice.breed_and_colour}"
|
94
|
+
|
95
|
+
if pet_choice.can_live_with
|
96
|
+
puts "Can live with: ".light_white + "#{pet_choice.can_live_with}"
|
97
|
+
end
|
98
|
+
|
99
|
+
puts "Bio: ".light_white + "#{pet_choice.bio}"
|
100
|
+
puts "Animal reference number: ".light_white + "#{pet_choice.reference}"
|
101
|
+
puts "Visit my page: ".light_white + "#{pet_choice.profile_url}"
|
102
|
+
end
|
103
|
+
|
66
104
|
def goodbye
|
67
105
|
puts "Thanks for stopping by! Have a great day!".blue.bold
|
68
106
|
text = <<-TEXT
|
data/lib/blue_cross_pets/dog.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative "./pet"
|
1
|
+
#require_relative "./pet"
|
2
2
|
|
3
3
|
class BlueCrossPets::Dog < BlueCrossPets::Pet
|
4
4
|
|
@@ -16,48 +16,15 @@ class BlueCrossPets::Dog < BlueCrossPets::Pet
|
|
16
16
|
@@dogs
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.
|
20
|
-
self.all.
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.scrape_dogs
|
19
|
+
def self.sorted_array
|
20
|
+
self.all.sort { |dog1, dog2| dog1.name <=> dog2.name }
|
21
|
+
end
|
26
22
|
|
23
|
+
def self.create_dogs
|
27
24
|
if all.length == 0
|
28
|
-
dog_array = BlueCrossPets::Scraper.scrape_index("https://www.bluecross.org.uk/rehome/dog")
|
25
|
+
dog_array = BlueCrossPets::Scraper.new.scrape_index("https://www.bluecross.org.uk/rehome/dog")
|
29
26
|
create_from_index(dog_array)
|
30
|
-
list_all
|
31
|
-
elsif all.length > 0
|
32
|
-
list_all
|
33
27
|
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.get_more_info(input)
|
38
|
-
|
39
|
-
index = input.to_i - 1
|
40
|
-
dog = all[index]
|
41
|
-
|
42
|
-
if !dog.reference
|
43
|
-
attribute_hash = BlueCrossPets::Scraper.scrape_profile(dog.profile_url)
|
44
|
-
dog.add_attributes(attribute_hash)
|
45
|
-
elsif dog.reference
|
46
|
-
end
|
47
|
-
|
48
|
-
puts "----------------------------- All about #{dog.name} -----------------------------".blue
|
49
|
-
puts "Age: ".light_white + "#{dog.age}"
|
50
|
-
puts "Gender: ".light_white + "#{dog.gender}"
|
51
|
-
puts "Availability: ".light_white + "#{dog.availability}"
|
52
|
-
puts "Breed & colour: ".light_white + "#{dog.breed_and_colour}"
|
53
|
-
|
54
|
-
if dog.can_live_with
|
55
|
-
puts "Can live with: ".light_white + "#{dog.can_live_with}"
|
56
|
-
end
|
57
|
-
|
58
|
-
puts "Bio: ".light_white + "#{dog.bio}"
|
59
|
-
puts "Animal reference number: ".light_white + "#{dog.reference}"
|
60
|
-
puts "Visit my page: ".light_white + "#{dog.profile_url}"
|
61
28
|
end
|
62
29
|
|
63
30
|
end
|
data/lib/blue_cross_pets/pet.rb
CHANGED
@@ -8,6 +8,13 @@ class BlueCrossPets::Pet
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
def get_more_info
|
12
|
+
if !self.reference
|
13
|
+
attribute_hash = BlueCrossPets::Scraper.new.scrape_profile(self.profile_url)
|
14
|
+
self.add_attributes(attribute_hash)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
11
18
|
def add_attributes(attribute_hash)
|
12
19
|
attribute_hash.each do |attribute, value|
|
13
20
|
self.send("#{attribute}=".to_sym, value)
|
@@ -1,14 +1,11 @@
|
|
1
1
|
class BlueCrossPets::Scraper
|
2
2
|
|
3
|
-
def
|
3
|
+
def scrape_index(index_url)
|
4
4
|
html = open(index_url)
|
5
5
|
|
6
6
|
pet_index = Nokogiri::HTML(html)
|
7
|
-
|
8
|
-
|
9
|
-
profile_url =
|
10
|
-
|
11
|
-
pet_index.css("a.item__link").each do |pet_info|
|
7
|
+
|
8
|
+
pet_index.css("a.item__link").collect do |pet_info|
|
12
9
|
name = pet_info.css("h3.item__title").text
|
13
10
|
breed = pet_info.css("ul.item__body li")[0].text
|
14
11
|
gender = pet_info.css("ul.item__body li")[1].text
|
@@ -21,20 +18,16 @@ class BlueCrossPets::Scraper
|
|
21
18
|
availability = "Available"
|
22
19
|
end
|
23
20
|
|
24
|
-
|
21
|
+
{name: name, breed: breed, gender: gender, age: age, profile_url: profile_url, availability: availability}
|
25
22
|
end
|
26
|
-
|
27
|
-
pets
|
28
23
|
end
|
29
24
|
|
30
|
-
def
|
25
|
+
def scrape_profile(profile_url)
|
31
26
|
pet_profile = Nokogiri::HTML(open(profile_url))
|
32
27
|
|
33
28
|
attributes_hash = {}
|
34
29
|
|
35
|
-
|
36
|
-
attributes_hash[:bio] = pet_profile.css("div.column-main p").text
|
37
|
-
end
|
30
|
+
attributes_hash[:bio] = pet_profile.css("div.column-main p").text
|
38
31
|
|
39
32
|
pet_profile.css("div.column-aside").each do |attribute|
|
40
33
|
attributes_hash[:breed_and_colour] = attribute.css("li.pet-details_species").text.split(" - ")[1].strip
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blue_cross_pets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "'Jessica Gomes-Ng'"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
|
-
rubygems_version: 3.0.
|
139
|
+
rubygems_version: 3.0.8
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: CLI that display Blue Cross UK adoptable dogs/cats
|