Class: Rotten::Cast
Instance Attribute Summary collapse
-
#actors ⇒ Object
readonly
Returns the value of attribute actors.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each {|@characters| ... } ⇒ Object
-
#include?(other) ⇒ Boolean
Check if this cast includes other Cast or Actor.
-
#initialize(array = []) ⇒ Cast
constructor
A new instance of Cast.
- #inspect ⇒ Object
- #process(array) ⇒ Object
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
#actors ⇒ Object (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
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
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 |
#inspect ⇒ Object
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 |