Class: CEML::Castable

Inherits:
Struct
  • Object
show all
Defined in:
lib/ceml/models/castable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bundle_idObject

Returns the value of attribute bundle_id

Returns:

  • (Object)

    the current value of bundle_id



2
3
4
# File 'lib/ceml/models/castable.rb', line 2

def bundle_id
  @bundle_id
end

#bytecodeObject

Returns the value of attribute bytecode

Returns:

  • (Object)

    the current value of bytecode



2
3
4
# File 'lib/ceml/models/castable.rb', line 2

def bytecode
  @bytecode
end

#matchingObject

Returns the value of attribute matching

Returns:

  • (Object)

    the current value of matching



2
3
4
# File 'lib/ceml/models/castable.rb', line 2

def matching
  @matching
end

#radiusObject

Returns the value of attribute radius

Returns:

  • (Object)

    the current value of radius



2
3
4
# File 'lib/ceml/models/castable.rb', line 2

def radius
  @radius
end

#rolesObject

Returns the value of attribute roles

Returns:

  • (Object)

    the current value of roles



2
3
4
# File 'lib/ceml/models/castable.rb', line 2

def roles
  @roles
end

#stanza_nameObject

Returns the value of attribute stanza_name

Returns:

  • (Object)

    the current value of stanza_name



2
3
4
# File 'lib/ceml/models/castable.rb', line 2

def stanza_name
  @stanza_name
end

#timewindowObject

Returns the value of attribute timewindow

Returns:

  • (Object)

    the current value of timewindow



2
3
4
# File 'lib/ceml/models/castable.rb', line 2

def timewindow
  @timewindow
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



2
3
4
# File 'lib/ceml/models/castable.rb', line 2

def type
  @type
end

Instance Method Details



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_roomsObject



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.tagspec.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.tagspec.with.empty?
    result.concat role.tagspec.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