Class: CEML::Player
- Inherits:
-
Struct
- Object
- Struct
- CEML::Player
- Includes:
- Redis::Objects
- Defined in:
- lib/ceml/models/player.rb
Constant Summary collapse
- MSG_PARAMS =
[:received, :recognized, :situation]
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
-
.update(bundle_id, player, cb_obj, &blk) ⇒ Object
= data = ========.
Instance Method Summary collapse
- #clear_answers ⇒ Object
- #clear_incident(id) ⇒ Object
- #merge_new_player_data(player) ⇒ Object
- #reset ⇒ Object
- #split(player) ⇒ Object
- #top_incident ⇒ Object
- #top_incident_id ⇒ Object
-
#touch(incident_id) ⇒ Object
= incidents = =============.
- #update(player, cb_obj) ⇒ Object
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id
2 3 4 |
# File 'lib/ceml/models/player.rb', line 2 def id @id end |
Class Method Details
.update(bundle_id, player, cb_obj, &blk) ⇒ Object
data =
42 43 44 45 |
# File 'lib/ceml/models/player.rb', line 42 def self.update bundle_id, player, cb_obj, &blk player[:bundle_id] = player[:squad_id] = bundle_id new(player[:id].to_s).update player, cb_obj, &blk end |
Instance Method Details
#clear_answers ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/ceml/models/player.rb', line 47 def clear_answers updating_lock.lock do value = data.value || {} value.delete(:qs_answers) value.delete(:received) data.value = value end end |
#clear_incident(id) ⇒ Object
33 34 35 |
# File 'lib/ceml/models/player.rb', line 33 def clear_incident(id) current_incidents.delete(id) end |
#merge_new_player_data(player) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/ceml/models/player.rb', line 64 def merge_new_player_data player updating_lock.lock do old_value = data.value || {} new_value = old_value.merge player new_value[:qs_answers] = (old_value[:qs_answers]||{}).merge(player[:qs_answers] || {}) # puts "SAVING DATA: #{new_value.inspect}" data.value = new_value end end |
#reset ⇒ Object
9 10 11 12 13 |
# File 'lib/ceml/models/player.rb', line 9 def reset data.clear .clear current_incidents.clear end |
#split(player) ⇒ Object
58 59 60 61 62 |
# File 'lib/ceml/models/player.rb', line 58 def split player = player.like(*MSG_PARAMS) MSG_PARAMS.each{ |p| player.delete(p) } return , player end |
#top_incident ⇒ Object
27 28 29 30 31 |
# File 'lib/ceml/models/player.rb', line 27 def top_incident if iid = top_incident_id IncidentModel.new(iid) end end |
#top_incident_id ⇒ Object
23 24 25 |
# File 'lib/ceml/models/player.rb', line 23 def top_incident_id current_incidents.last end |
#touch(incident_id) ⇒ Object
incidents =
19 20 21 |
# File 'lib/ceml/models/player.rb', line 19 def touch(incident_id) current_incidents[incident_id] = Time.now.to_i end |
#update(player, cb_obj) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ceml/models/player.rb', line 74 def update player, cb_obj player = player.dup # puts "UPDATING player id #{id} with #{player.inspect}" , player = split(player) merge_new_player_data(player) cmd = [:recognized] if cmd and cb_obj and cb_obj.recognize_override(cmd, , player, self) .delete else .value = yield player if block_given? end end |