Class: CARPS::ClientTurn

Inherits:
Message show all
Defined in:
lib/carps/mod/client_turn.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

#crypt, #crypt=, #delete, #from, #from=, #parse, #path=, #save, #session, #session=

Constructor Details

#initialize(sheet, status, questions) ⇒ ClientTurn

Create a client turn



32
33
34
35
36
# File 'lib/carps/mod/client_turn.rb', line 32

def initialize sheet, status, questions
   @sheet = sheet
   @status = status
   @questions = questions
end

Class Method Details

.parse(blob) ⇒ Object

Parse



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/carps/mod/client_turn.rb', line 44

def ClientTurn.parse blob
   forget, blob = find K.client_turn, blob
   sheet, blob = Sheet::NewSheet.parse blob
   status, blob = StatusReport.parse blob
   more = true
   questions = []
   while more
      begin
         que, blob = Question.parse blob
         questions.push que
      rescue Expected
         more = false
      end
   end
   [ClientTurn.new(sheet, status, questions), blob] 
end

Instance Method Details

#emitObject

Emit



62
63
64
65
66
# File 'lib/carps/mod/client_turn.rb', line 62

def emit
   question_text = (@questions.map {|q| q.emit}).join
   status = @status.emit
   K.client_turn + @sheet.emit + status + question_text
end

#previewObject

Preview the turn



69
70
71
72
73
74
# File 'lib/carps/mod/client_turn.rb', line 69

def preview
   @status.display
   @questions.each do |q|
      q.preview
   end
end

#sheetObject

Expose the character sheet



39
40
41
# File 'lib/carps/mod/client_turn.rb', line 39

def sheet
   @sheet
end

#takeObject

Take the turn, return list of answers



77
78
79
80
81
82
83
84
# File 'lib/carps/mod/client_turn.rb', line 77

def take
   @status.display
   answers = Answers.new
   @questions.each do |q|
      q.ask answers
   end
   answers
end