Class: DiscoverDogBreeds::Scrape
- Inherits:
-
Object
- Object
- DiscoverDogBreeds::Scrape
- Defined in:
- lib/discover_dog_breeds/scrape.rb
Constant Summary collapse
- URL =
"http://www.akc.org/dog-breeds"
Instance Method Summary collapse
- #get_dog_details_by_name(name) ⇒ Object
- #get_dog_list_by_letter(letter) ⇒ Object
-
#get_html(arg, type) ⇒ Object
Scrape#get_html returns an array of dog names by letter (with last element removed, which is a Nokogiri element node with no data).
Instance Method Details
#get_dog_details_by_name(name) ⇒ Object
9 10 11 12 |
# File 'lib/discover_dog_breeds/scrape.rb', line 9 def get_dog_details_by_name(name) result = get_html("#{name}", "name_search") result.size > 0 ? result.collect { |detail| detail.text.split(":")[1].strip } : [] end |
#get_dog_list_by_letter(letter) ⇒ Object
4 5 6 7 |
# File 'lib/discover_dog_breeds/scrape.rb', line 4 def get_dog_list_by_letter(letter) result = get_html("?letter=#{letter}", "az_search") result.collect { |dog| dog.css('.scale-contents h2 a').text }[0..-2] end |
#get_html(arg, type) ⇒ Object
Scrape#get_html returns an array of dog names by letter (with last element removed, which is a Nokogiri element node with no data)
15 16 17 18 |
# File 'lib/discover_dog_breeds/scrape.rb', line 15 def get_html(arg, type) search = type == "az_search" ? "div.event-contain .event" : "div.breed-details__main li" Nokogiri::HTML(open("#{URL}/#{arg}")).css(search) end |