Class: XxxRename::ActorsHelper

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/xxx_rename/actors_helper.rb

Instance Method Summary collapse

Instance Method Details

#append_female(actor_hash) ⇒ Object



23
24
25
# File 'lib/xxx_rename/actors_helper.rb', line 23

def append_female(actor_hash)
  female_actors[actor_hash["compressed_name"]] = actor_hash["name"] if female_actors[actor_hash["compressed_name"]].nil?
end

#append_male(actor_hash) ⇒ Object



27
28
29
# File 'lib/xxx_rename/actors_helper.rb', line 27

def append_male(actor_hash)
  male_actors[actor_hash["compressed_name"]] = actor_hash["name"] if male_actors[actor_hash["compressed_name"]].nil?
end

#auto_fetch(actor) ⇒ Object



66
67
68
69
70
71
# File 'lib/xxx_rename/actors_helper.rb', line 66

def auto_fetch(actor)
  auto_fetch!(actor)
rescue Errors::UnprocessedEntity => e
  XxxRename.logger.warn "Unable to fetch details for #{e.message}"
  nil
end

#auto_fetch!(actor) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/xxx_rename/actors_helper.rb', line 57

def auto_fetch!(actor)
  details = fetch_actor_details.details(actor)

  raise Errors::UnprocessedEntity, actor if details.nil?

  details["gender"].downcase == "female" ? append_female(details) : append_male(details)
  nil
end

#female?(actor) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/xxx_rename/actors_helper.rb', line 38

def female?(actor)
  processed!(actor)
  female_actors.key? actor.normalize
rescue Errors::UnprocessedEntity
  false
end

#female_actorsObject



15
16
17
# File 'lib/xxx_rename/actors_helper.rb', line 15

def female_actors
  @female_actors ||= {}
end

#male?(actor) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
# File 'lib/xxx_rename/actors_helper.rb', line 31

def male?(actor)
  processed!(actor)
  male_actors.key? actor.normalize
rescue Errors::UnprocessedEntity
  false
end

#male_actorsObject



19
20
21
# File 'lib/xxx_rename/actors_helper.rb', line 19

def male_actors
  @male_actors ||= {}
end

#matcher(matcher = nil) ⇒ Object

Raises:



9
10
11
12
13
# File 'lib/xxx_rename/actors_helper.rb', line 9

def matcher(matcher = nil)
  raise Errors::FatalError, "#{self.class.name} initialised without matcher" if @matcher.nil? && matcher.nil?

  @matcher ||= matcher
end

#processed!(actor) ⇒ Object



51
52
53
54
55
# File 'lib/xxx_rename/actors_helper.rb', line 51

def processed!(actor)
  return true if female_actors.key?(actor.normalize) || male_actors.key?(actor.normalize)

  raise Errors::UnprocessedEntity, actor
end

#processed?(actor) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/xxx_rename/actors_helper.rb', line 45

def processed?(actor)
  processed!(actor)
rescue Errors::UnprocessedEntity
  false
end