Class: NowShowing::Show

Inherits:
Object
  • Object
show all
Defined in:
lib/now_showing/showing.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, weekend, gross, link, about = nil, metascore = nil) ⇒ Show

Returns a new instance of Show.



7
8
9
10
11
12
13
14
15
# File 'lib/now_showing/showing.rb', line 7

def initialize(name,weekend,gross,link,about=nil,metascore=nil)
  @name=name
  @weekend=weekend
  @gross=gross
  @link=link
  @about=about
  @metascore=metascore
  @@all << self
end

Instance Attribute Details

#aboutObject

Returns the value of attribute about.



3
4
5
# File 'lib/now_showing/showing.rb', line 3

def about
  @about
end

#grossObject

Returns the value of attribute gross.



3
4
5
# File 'lib/now_showing/showing.rb', line 3

def gross
  @gross
end

Returns the value of attribute link.



3
4
5
# File 'lib/now_showing/showing.rb', line 3

def link
  @link
end

#metascoreObject

Returns the value of attribute metascore.



3
4
5
# File 'lib/now_showing/showing.rb', line 3

def metascore
  @metascore
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/now_showing/showing.rb', line 3

def name
  @name
end

#weekendObject

Returns the value of attribute weekend.



3
4
5
# File 'lib/now_showing/showing.rb', line 3

def weekend
  @weekend
end

Class Method Details

.allObject



32
33
34
# File 'lib/now_showing/showing.rb', line 32

def self.all
  @@all
end

.more_info(movie) ⇒ Object

scrapes movie page for addtional movie info



41
42
43
44
45
# File 'lib/now_showing/showing.rb', line 41

def self.more_info(movie)
  doc = Nokogiri::HTML(open(movie.link))
  movie.about = doc.css('.summary_text').text.gsub("\n",' ').squeeze(' ')
  movie.metascore = doc.css('.metacriticScore').text.gsub("\n",' ').squeeze(' ')
end

.resetObject



36
37
38
# File 'lib/now_showing/showing.rb', line 36

def self.reset
  self.all.clear
end

.scrape_now_showingObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/now_showing/showing.rb', line 17

def self.scrape_now_showing
  doc = Nokogiri::HTML(open("http://www.imdb.com/chart/boxoffice?ref_=nv_ch_cht_1 "))
  doc.css("#boxoffice").css('tr').each do |movie|
    #checks if the table row contains movie info
    if movie.css('.ratingColumn')[0] && movie.css('.titleColumn') && movie.css('.ratingColumn')[1]
      name = movie.css('.titleColumn').text.gsub("\n",' ').squeeze(' ')
      weekend = movie.css('.ratingColumn')[0].text.gsub("\n",' ').squeeze(' ')
      gross = movie.css('.ratingColumn')[1].text.gsub("\n",' ').squeeze(' ')
      link="http://www.imdb.com#{movie.css(".posterColumn").css('td')[0].css('a')[0]['href']}"
      self.new(name,weekend,gross,link)
    end
  end
end