-
Notifications
You must be signed in to change notification settings - Fork 0
/
d1e03_tvshows.rb
84 lines (62 loc) · 1.76 KB
/
d1e03_tvshows.rb
1
2
3
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#encoding: utf-8
require 'imdb'
require 'awesome_print'
class Serie
attr_reader :title, :rating, :seasons, :episodes
def initialize(title, rating, seasons, episodes)
@title = title
@rating = rating
@seasons = seasons
@episodes = episodes
end
end
class Reader
def initialize(tvshows_src)
series_file = IO.read(tvshows_src)
@series_titles = series_file.split("\n") #Array of movies titles.
@series_data = []
#Other way using readlines like
@series_data = @series_titles.map do |title|
Searcher.new.get_serie_info(title)
end
end
#most_seasons_from
# puts most_episodes_from
def most_seasons_from
@series_data.sort {|a,b| a.seasons <=> b.seasons}.last.title.to_s
end
def most_episodes_from
@series_data.sort {|a,b| a.episodes <=> b.episodes}.last.title
#@series_data.sort_by episodes
end
def best_rated
@series_data.sort {|a,b| a.rating <=> b.rating}.last.title
end
# def top_list
# @series_data.sort {|a,b| a.rating <=> b.rating}
# end
def result_count(word)
Imdb::Search.new(word).movies.size
end
end
class Searcher
def get_serie_info(title)
series_instances = Imdb::Search.new(title).movies.first
series_data = Imdb::Serie.new(series_instances.id) #OK
id = series_data.id
rating = series_data.rating
seasons = series_data.seasons.size # Max season number
season_counter = 0
episodes = 0
while season_counter < seasons
season_counter += 1
episodes += series_data.season(season_counter).episodes.size #Depende del número de seasons
end
episodes
Serie.new(title, rating, seasons, episodes)
end
end
#series_reader = Reader.new("tvshows.txt")
#puts series_reader.show_info
# dexter_movie =Imdb::Search.new(‘Dexter’).movies.first
# dexter_serie = Imdb::Serie.new(dexter_movie.id)