Class: ReligioCLI::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/religio_cli/scraper.rb

Class Method Summary collapse

Class Method Details

.initiate_scraperObject



3
4
5
6
7
8
# File 'lib/religio_cli/scraper.rb', line 3

def self.initiate_scraper
  ReligioCLI::Trads.create_from_array(religion_scraper)
  ReligioCLI::Trads.all.each do |religion|
    religion.religion_details(religion_scraper_details(religion.url))
  end
end

.religion_scraperObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/religio_cli/scraper.rb', line 10

def self.religion_scraper
  doc = Nokogiri::HTML(open("https://www.patheos.com/library"))
  religion_hashes = []
  doc.css("div.col-lg-3.col-md-4.col-xs-6.remove-padding.related-content.colored.brand-prime-1.religionSquare").each do |content|
    name = content.css("h2.remove-margin.over-dark.text-uppercase").text
    quick_facts = content.css("div.details.text-uppercase").text.strip.gsub("Origin", "origin\:").gsub("adherents", "adherents\:").gsub("Formed", "formed\:").gsub("\r\n "+"                        ","").upcase
    url = content.css("a").map{ |link| link['href'] }[0]
    religion_hashes << {:name => name, :url => url, :quick_facts => quick_facts}
  end
  religion_hashes
end

.religion_scraper_details(url) ⇒ Object



22
23
24
25
26
27
# File 'lib/religio_cli/scraper.rb', line 22

def self.religion_scraper_details(url)
  doc = Nokogiri::HTML(open(url))
  description = doc.css("div.dropcap.buffer-bottom").text.strip!
  religion_details = {:description => description}
  religion_details
end