Class: WhatsOnNetflix::List

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

Direct Known Subclasses

ComingSoon, LeavingSoon

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(display_title) ⇒ List

Returns a new instance of List.



5
6
7
# File 'lib/whats_on_netflix/list.rb', line 5

def initialize(display_title)
    @display_title = display_title
end

Instance Attribute Details

#display_titleObject

Returns the value of attribute display_title.



3
4
5
# File 'lib/whats_on_netflix/list.rb', line 3

def display_title
  @display_title
end

#genreObject

Returns the value of attribute genre.



3
4
5
# File 'lib/whats_on_netflix/list.rb', line 3

def genre
  @genre
end

#plotObject

Returns the value of attribute plot.



3
4
5
# File 'lib/whats_on_netflix/list.rb', line 3

def plot
  @plot
end

#starsObject

Returns the value of attribute stars.



3
4
5
# File 'lib/whats_on_netflix/list.rb', line 3

def stars
  @stars
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/whats_on_netflix/list.rb', line 3

def title
  @title
end

#yearObject

Returns the value of attribute year.



3
4
5
# File 'lib/whats_on_netflix/list.rb', line 3

def year
  @year
end

Class Method Details

.add_moviesObject



9
10
11
# File 'lib/whats_on_netflix/list.rb', line 9

def self.add_movies
    self.create_from_array(WhatsOnNetflix::Scraper.scrape_title_list(self.list_url))
end

.create_from_array(array) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/whats_on_netflix/list.rb', line 13

def self.create_from_array(array)
    array.each do |entry|
        movie = self.new(entry)
        new_title = entry.split("(")
        movie.title = new_title[0].strip
        self.all << movie
    end
end

.current_monthObject

used to generate current url for whats-on-netflix.com



31
32
33
# File 'lib/whats_on_netflix/list.rb', line 31

def self.current_month
    Date::MONTHNAMES[Date.today.month].downcase
end

.current_yearObject



35
36
37
# File 'lib/whats_on_netflix/list.rb', line 35

def self.current_year
    Date.today.year
end

.item(input) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/whats_on_netflix/list.rb', line 47

def self.item(input)
    movie = self.all[input.to_i - 1]
    movie.add_data_from_hash(WhatsOnNetflix::Scraper.scrape_imdb_info(movie.title))
    puts ""
    puts "---"
    puts "#{movie.title} - #{movie.year}" 
    puts "#{movie.genre}"
    puts "Starring #{movie.stars}"
    puts ""
    puts "#{movie.plot}"
    movie
end

CLI printers



41
42
43
44
45
# File 'lib/whats_on_netflix/list.rb', line 41

def self.print_list
    self.all.each_with_index do |movie, index|
        puts "#{index + 1}. #{movie.display_title}"
    end
end

Instance Method Details

#add_data_from_hash(hash) ⇒ Object



22
23
24
25
26
27
# File 'lib/whats_on_netflix/list.rb', line 22

def add_data_from_hash(hash)
    self.year = hash[:year]
    self.genre = hash[:genre]
    self.stars = hash[:stars]
    self.plot = hash[:plot]
end