Class: TrendingEntertainmentCliApp::DetailsScraper

Inherits:
Object
  • Object
show all
Defined in:
lib/trending_entertainment_cli_app/details_scraper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



2
3
4
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 2

def category
  @category
end

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 2

def description
  @description
end

#infoObject

Returns the value of attribute info.



2
3
4
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 2

def info
  @info
end

#ratingObject

Returns the value of attribute rating.



2
3
4
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 2

def rating
  @rating
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/trending_entertainment_cli_app/details_scraper.rb', line 2

def title
  @title
end

#yearObject

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.rating = 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.rating}", "")}"
  puts ""
  puts "--- YEAR ---"
  puts "#{specific.year}"
  puts ""
  puts "--- CONTENT RATING ---"
  puts "#{specific.rating}"
  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