class WhatAWorld::Scraper::ScraperIssues

Attributes

country_page[RW]
disputes_content[R]
disputes_hash[RW]
drugs_content[R]
drugs_hash[RW]
refugees_content[R]
refugees_hash[RW]
trafficking_content[R]
trafficking_hash[RW]

Public Class Methods

new(url_extension) click to toggle source
# File lib/what_a_world/scraper.rb, line 68
def initialize(url_extension)
    @disputes_content = []
    @refugees_content = []
    @trafficking_content = []
    @drugs_content = []
    @trafficking_hash = {}
    @disputes_hash = {}
    @drugs_hash = {}
    @refugees_hash = {}
    country_url = URL + modify_extension(url_extension)
    html = open(country_url)
    @country_page = Nokogiri::HTML(html)
end

Public Instance Methods

add_content(iterator, content) click to toggle source
# File lib/what_a_world/scraper.rb, line 116
def add_content(iterator, content)
    iterator +=1
    scraped = scraped_string(iterator)
    while scraped != @@disputes && scraped != @@refugees && scraped != @@trafficking && scraped != @@drugs && scraped != nil
        content << scraped
        iterator +=1
        scraped = scraped_string(iterator)
    end
    iterator
end
modify_extension(url_extension) click to toggle source
# File lib/what_a_world/scraper.rb, line 82
def modify_extension(url_extension)
    mod_extension = url_extension.split("/")
    mod_extension = mod_extension.insert(1, "/")
    mod_extension = mod_extension.insert(2, "print_")
    mod_extension = mod_extension.join
end
scrape_issues() click to toggle source
# File lib/what_a_world/scraper.rb, line 93
def scrape_issues
    iterator = 0
    scraped_string(iterator)
    finished = false
    while !finished
        if  @@disputes == scraped_string(iterator)
            iterator = add_content(iterator, self.disputes_content)
        elsif @@refugees == scraped_string(iterator)
            iterator = add_content(iterator, self.refugees_content)
        elsif @@trafficking == scraped_string(iterator)
            iterator = add_content(iterator, self.trafficking_content)
        elsif @@drugs == scraped_string(iterator)
            iterator = add_content(iterator, self.drugs_content)
        else
            finished = true
        end 
    end
self.disputes_hash[@@disputes] = self.disputes_content
self.refugees_hash[@@refugees] = self.refugees_content
self.trafficking_hash[@@trafficking] = self.trafficking_content
self.drugs_hash[@@drugs] = self.drugs_content
end
scraped_string(iterator) click to toggle source
# File lib/what_a_world/scraper.rb, line 89
def scraped_string(iterator)
    @country_page.css("li").last.css("div")[iterator].text.strip if @country_page.css("li").last.css("div")[iterator]
end