Class: WhatAWorld::Scraper::ScraperIssues
- Inherits:
-
Object
- Object
- WhatAWorld::Scraper::ScraperIssues
- Defined in:
- lib/what_a_world/scraper.rb
Constant Summary collapse
- @@disputes =
"Disputes - international:"
- @@refugees =
"Refugees and internally displaced persons:"
- @@trafficking =
"Trafficking in persons:"
- @@drugs =
"Illicit drugs:"
Instance Attribute Summary collapse
-
#country_page ⇒ Object
Returns the value of attribute country_page.
-
#disputes_content ⇒ Object
readonly
Returns the value of attribute disputes_content.
-
#disputes_hash ⇒ Object
Returns the value of attribute disputes_hash.
-
#drugs_content ⇒ Object
readonly
Returns the value of attribute drugs_content.
-
#drugs_hash ⇒ Object
Returns the value of attribute drugs_hash.
-
#refugees_content ⇒ Object
readonly
Returns the value of attribute refugees_content.
-
#refugees_hash ⇒ Object
Returns the value of attribute refugees_hash.
-
#trafficking_content ⇒ Object
readonly
Returns the value of attribute trafficking_content.
-
#trafficking_hash ⇒ Object
Returns the value of attribute trafficking_hash.
Instance Method Summary collapse
- #add_content(iterator, content) ⇒ Object
-
#initialize(url_extension) ⇒ ScraperIssues
constructor
A new instance of ScraperIssues.
- #modify_extension(url_extension) ⇒ Object
- #scrape_issues ⇒ Object
- #scraped_string(iterator) ⇒ Object
Constructor Details
#initialize(url_extension) ⇒ ScraperIssues
Returns a new instance of ScraperIssues.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# 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 |
Instance Attribute Details
#country_page ⇒ Object
Returns the value of attribute country_page.
66 67 68 |
# File 'lib/what_a_world/scraper.rb', line 66 def country_page @country_page end |
#disputes_content ⇒ Object (readonly)
Returns the value of attribute disputes_content.
67 68 69 |
# File 'lib/what_a_world/scraper.rb', line 67 def disputes_content @disputes_content end |
#disputes_hash ⇒ Object
Returns the value of attribute disputes_hash.
66 67 68 |
# File 'lib/what_a_world/scraper.rb', line 66 def disputes_hash @disputes_hash end |
#drugs_content ⇒ Object (readonly)
Returns the value of attribute drugs_content.
67 68 69 |
# File 'lib/what_a_world/scraper.rb', line 67 def drugs_content @drugs_content end |
#drugs_hash ⇒ Object
Returns the value of attribute drugs_hash.
66 67 68 |
# File 'lib/what_a_world/scraper.rb', line 66 def drugs_hash @drugs_hash end |
#refugees_content ⇒ Object (readonly)
Returns the value of attribute refugees_content.
67 68 69 |
# File 'lib/what_a_world/scraper.rb', line 67 def refugees_content @refugees_content end |
#refugees_hash ⇒ Object
Returns the value of attribute refugees_hash.
66 67 68 |
# File 'lib/what_a_world/scraper.rb', line 66 def refugees_hash @refugees_hash end |
#trafficking_content ⇒ Object (readonly)
Returns the value of attribute trafficking_content.
67 68 69 |
# File 'lib/what_a_world/scraper.rb', line 67 def trafficking_content @trafficking_content end |
#trafficking_hash ⇒ Object
Returns the value of attribute trafficking_hash.
66 67 68 |
# File 'lib/what_a_world/scraper.rb', line 66 def trafficking_hash @trafficking_hash end |
Instance Method Details
#add_content(iterator, content) ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# 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) ⇒ Object
82 83 84 85 86 87 |
# 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 ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# 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) ⇒ Object
89 90 91 |
# 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 |