Class: CEML::Castable
- Inherits:
-
Struct
- Object
- Struct
- CEML::Castable
- Defined in:
- lib/ceml/models/castable.rb
Instance Attribute Summary collapse
-
#bundle_id ⇒ Object
Returns the value of attribute bundle_id.
-
#bytecode ⇒ Object
Returns the value of attribute bytecode.
-
#matching ⇒ Object
Returns the value of attribute matching.
-
#radius ⇒ Object
Returns the value of attribute radius.
-
#roles ⇒ Object
Returns the value of attribute roles.
-
#stanza_name ⇒ Object
Returns the value of attribute stanza_name.
-
#timewindow ⇒ Object
Returns the value of attribute timewindow.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #advertise_roles(incident_id, cast) ⇒ Object
- #all_rooms ⇒ Object
-
#cast_from(guys) ⇒ Object
an O(n*^2) alg for now.
- #hot_waiting_rooms_given_player(player, seeded = false) ⇒ Object
- #waiting_rooms_for_player(player, seeded = false) ⇒ Object
- #waiting_rooms_to_watch(role, cast) ⇒ Object
- #with_open_roles(cast) ⇒ Object
Instance Attribute Details
#bundle_id ⇒ Object
Returns the value of attribute bundle_id
2 3 4 |
# File 'lib/ceml/models/castable.rb', line 2 def bundle_id @bundle_id end |
#bytecode ⇒ Object
Returns the value of attribute bytecode
2 3 4 |
# File 'lib/ceml/models/castable.rb', line 2 def bytecode @bytecode end |
#matching ⇒ Object
Returns the value of attribute matching
2 3 4 |
# File 'lib/ceml/models/castable.rb', line 2 def matching @matching end |
#radius ⇒ Object
Returns the value of attribute radius
2 3 4 |
# File 'lib/ceml/models/castable.rb', line 2 def radius @radius end |
#roles ⇒ Object
Returns the value of attribute roles
2 3 4 |
# File 'lib/ceml/models/castable.rb', line 2 def roles @roles end |
#stanza_name ⇒ Object
Returns the value of attribute stanza_name
2 3 4 |
# File 'lib/ceml/models/castable.rb', line 2 def stanza_name @stanza_name end |
#timewindow ⇒ Object
Returns the value of attribute timewindow
2 3 4 |
# File 'lib/ceml/models/castable.rb', line 2 def timewindow @timewindow end |
#type ⇒ Object
Returns the value of attribute type
2 3 4 |
# File 'lib/ceml/models/castable.rb', line 2 def type @type end |
Instance Method Details
#advertise_roles(incident_id, cast) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/ceml/models/castable.rb', line 4 def advertise_roles(incident_id, cast) with_open_roles(cast) do |idx, role, count| waiting_rooms_to_watch(role, cast).each do |room| room.list_job(incident_id, idx, role.name, count) end end end |
#all_rooms ⇒ Object
42 43 44 |
# File 'lib/ceml/models/castable.rb', line 42 def all_rooms roles.map{ |r| waiting_rooms_to_watch(r, {}) }.flatten end |
#cast_from(guys) ⇒ Object
an O(n*^2) alg for now. can do much better
55 56 57 58 59 60 61 |
# File 'lib/ceml/models/castable.rb', line 55 def cast_from guys # see if we can build a cast out of them and bid on the casts possible_casts = guys.map{ |guy| Cast.new self, guy }.select(&:star) guys.each{ |guy| possible_casts.each{ |cast| cast.cast guy }} result = possible_casts.detect(&:launchable?) result end |
#hot_waiting_rooms_given_player(player, seeded = false) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/ceml/models/castable.rb', line 20 def hot_waiting_rooms_given_player(player, seeded=false) rooms = waiting_rooms_for_player(player, seeded) roles.each{ |r| rooms.concat(["#{bundle_id}:#{stanza_name}:#{r.name}", *r..with]) } rooms << "#{bundle_id}:#{stanza_name}:*" # rooms << 'generic' rooms.uniq end |
#waiting_rooms_for_player(player, seeded = false) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/ceml/models/castable.rb', line 12 def waiting_rooms_for_player(player, seeded=false) result = [] result.concat([*player[:seeded]]) if player[:seeded] result.concat player[:tags] if player[:tags] unless seeded # result << 'generic' result end |
#waiting_rooms_to_watch(role, cast) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ceml/models/castable.rb', line 28 def waiting_rooms_to_watch(role, cast) # skip for now: radius, timewindow, matching, general result = [] if stanza_name result << "#{bundle_id}:#{stanza_name}:#{role.name}" result << "#{bundle_id}:#{stanza_name}:*" end if !role..with.empty? result.concat role..with end # result << 'generic' result.map{ |id| WaitingRoom.new(id) } end |
#with_open_roles(cast) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/ceml/models/castable.rb', line 46 def with_open_roles(cast) roles.each_with_index do |role, i| count = cast.room(role) next unless count > 0 yield i, role, count end end |