Class: Rotten::Cast

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rotten/cast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array = []) ⇒ Cast

Returns a new instance of Cast.



6
7
8
9
10
# File 'lib/rotten/cast.rb', line 6

def initialize array=[]
  @actors     = Set.new
  @characters = []
  process (array || [])
end

Instance Attribute Details

#actorsObject (readonly)

Returns the value of attribute actors.



5
6
7
# File 'lib/rotten/cast.rb', line 5

def actors
  @actors
end

Instance Method Details

#[](index) ⇒ Object



16
17
18
# File 'lib/rotten/cast.rb', line 16

def [] index
  @characters[index]
end

#each {|@characters| ... } ⇒ Object

Yields:

  • (@characters)


28
29
30
# File 'lib/rotten/cast.rb', line 28

def each &block
  yield @characters
end

#include?(other) ⇒ Boolean

Check if this cast includes other Cast or Actor

Parameters:

  • The (Object other)

    target to be compared against.

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
# File 'lib/rotten/cast.rb', line 35

def include?(other)
  if other.is_a?(Cast)
    names = @actors.map(&:name)
    ( names - other.actors.map(&:name) ).empty?
  elsif other.is_a?(Actor)
    @actors.map(&:name).include?( other.name )
  else
    @characters.include?(other)
  end
end

#inspectObject



12
13
14
# File 'lib/rotten/cast.rb', line 12

def inspect
  "<Rotten::Cast actors='#{@actors.map(&:name)}'>"
end

#process(array) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/rotten/cast.rb', line 20

def process array
  array.each do |hash|
    actor      =  @actors.detect{|a| a.name == hash["name"] } || a=Actor.new; a.attributes=hash
    @actors     << actor
    @characters << [ actor, hash["characters"] ]
  end
end