Class: TopTv::Show

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url) ⇒ Show

Returns a new instance of Show.



13
14
15
16
17
# File 'lib/top_tv/show.rb', line 13

def initialize(name, url)
  @name = name
  @url = url
  @@all << self
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/top_tv/show.rb', line 2

def description
  @description
end

#genreObject

Returns the value of attribute genre.



2
3
4
# File 'lib/top_tv/show.rb', line 2

def genre
  @genre
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/top_tv/show.rb', line 2

def name
  @name
end

#networkObject

Returns the value of attribute network.



2
3
4
# File 'lib/top_tv/show.rb', line 2

def network
  @network
end

#premiere_dateObject

Returns the value of attribute premiere_date.



2
3
4
# File 'lib/top_tv/show.rb', line 2

def premiere_date
  @premiere_date
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/top_tv/show.rb', line 2

def url
  @url
end

Class Method Details

.allObject



19
20
21
# File 'lib/top_tv/show.rb', line 19

def self.all
  @@all
end

.find_show_by_name(chosen_show) ⇒ Object



23
24
25
# File 'lib/top_tv/show.rb', line 23

def self.find_show_by_name(chosen_show)
  self.all.detect { |show| show.name == chosen_show }
end

.new_from_home_page(show) ⇒ Object



6
7
8
9
10
11
# File 'lib/top_tv/show.rb', line 6

def self.new_from_home_page(show)
  self.new(
    show.text.gsub(" View All ", "").gsub(",", ""),
    "https://www.rottentomatoes.com#{show.attr("href")}"
  )
end

Instance Method Details

#docObject



43
44
45
# File 'lib/top_tv/show.rb', line 43

def doc
  @doc ||= Nokogiri::HTML(open(self.url))
end