Class: TrendingEntertainmentCliApp::DetailsScraper
- Inherits:
-
Object
- Object
- TrendingEntertainmentCliApp::DetailsScraper
- Defined in:
- lib/trending_entertainment_cli_app/details_scraper.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
Returns the value of attribute category.
-
#description ⇒ Object
Returns the value of attribute description.
-
#info ⇒ Object
Returns the value of attribute info.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#title ⇒ Object
Returns the value of attribute title.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
Instance Attribute Details
#category ⇒ Object
Returns the value of attribute category.
2 3 4 |
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 2 def category @category end |
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 2 def description @description end |
#info ⇒ Object
Returns the value of attribute info.
2 3 4 |
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 2 def info @info end |
#rating ⇒ Object
Returns the value of attribute rating.
2 3 4 |
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 2 def @rating end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 2 def title @title end |
#year ⇒ Object
Returns the value of attribute year.
2 3 4 |
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 2 def year @year end |
Class Method Details
.scrape_details(url) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 4 def self.scrape_details(url) specific = self.new details = Nokogiri::HTML(open(url)) specific.title = details.css("div.col-md-10.col-md-offset-2.col-sm-9.col-sm-offset-3.mobile-title h1").text.chomp.gsub(/(\d\d\d\d)/, "") specific.year = details.css("div.col-md-10.col-md-offset-2.col-sm-9.col-sm-offset-3.mobile-title h1 span.year").text specific. = details.css("div.col-md-10.col-md-offset-2.col-sm-9.col-sm-offset-3.mobile-title h1 div.certification").text specific.description = details.css("div.col-lg-8.col-md-7 div#overview").text specific.category = details.search("div.col-lg-8.col-md-7 li label").map{ |li| li.text}.drop(2) details.search("label").remove specific.info = details.css("div.col-lg-8.col-md-7 li").map{ |info| info.text}.drop(2) puts "" puts "--- TITLE ---" puts "#{specific.title.gsub("#{specific.}", "")}" puts "" puts "--- YEAR ---" puts "#{specific.year}" puts "" puts "--- CONTENT RATING ---" puts "#{specific.}" puts "" puts "--- DESCRIPTION ---" puts "#{specific.description}" puts "" puts "--- ADDITIONAL INFO ---" combined = specific.category.zip(specific.info).flatten.compact combined.each_slice(2).map { |each| puts "#{each.first} - #{each.last}"} puts "" end |