Class: TheWhos

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

Class Method Summary collapse

Class Method Details

.create(id) ⇒ Object



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

def self.create(id)
  if id.chr == 't'
    return Title.new(id)
  elsif id.chr == 'n'
    return Actor.new(id)
  else
    return 'Error'
  end
end

.match_actor(title_a, title_b) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/the_whos.rb', line 43

def self.match_actor(title_a, title_b)
  if title_a.class == String
    title_a = Title.new(title_a)
  end
  if title_b.class == String
    title_b = Title.new(title_b)
  end
  match = Array.new
  title_a.fullcast.each do |actor_a|
    title_b.fullcast.each do |actor_b|
      if actor_a[:id] == actor_b[:id]
        match << "#{actor_a[:actor].to_s} (#{actor_a[:id]})"
      end
    end
  end
  if match.empty? == true
    return 'Not Match'
  else
    return match
  end
end

.match_title(actor_a, actor_b) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/the_whos.rb', line 65

def self.match_title(actor_a, actor_b)
  if actor_a.class == String
    actor_a = Actor.new(actor_a)
  end
  if actor_b.class == String
    actor_b = Actor.new(actor_b)
  end
  match = Array.new
  actor_a.cast.each do |title_a|
    actor_b.cast.each do |title_b|
      if title_a[:id] == title_b[:id]
        match << "#{title_a[:title]} (#{title_a[:id]})"
      end
    end
  end
  if match.empty? == true
    return 'Not Match'
  else
    return match
  end
end

.search_actor(expression) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/the_whos.rb', line 30

def self.search_actor(expression)
  expression = expression.gsub(' ', '@')
  url = "https://imdb-api.com/en/API/SearchName/#{@key_imdb}/#{expression}"
  response = RestClient.get url
  r_json = JSON.parse response.to_str
  arr_search = r_json['results'].to_a
  results = Array.new
  arr_search.size.times do |i|
    results << {id: "#{arr_search[i]['id']}", title: "#{arr_search[i]['title']}"}
  end
  return results
end

.search_title(expression) ⇒ Object



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

def self.search_title(expression)
  expression = expression.gsub(' ', '@')
  url = "https://imdb-api.com/en/API/SearchTitle/#{@key_imdb}/#{expression}"
  response = RestClient.get url
  r_json = JSON.parse response.to_str
  arr_search = r_json['results'].to_a
  results = Array.new
  arr_search.size.times do |i|
    results << {id: "#{arr_search[i]['id']}", title: "#{arr_search[i]['title']}"}
  end
  return results
end

.who(title, actor) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/the_whos.rb', line 87

def self.who(title, actor)
  if title.class == String
    title = Title.new(title)
  end
  if actor.class == String
    actor = Actor.new(actor)
  end
  title.fullcast.each do |cast|
    if cast[:id] == actor.id
      return cast[:character]
    end
  end
  return 'not appear'
end