Class: CARPS::Answers

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

Overview

A series of answers to questions asked by the DM.

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(answers_hash = {}) ⇒ Answers

The answers hash gives the initial answers



35
36
37
# File 'lib/carps/mod/answers.rb', line 35

def initialize answers_hash = {}
   @answers = answers_hash
end

Class Method Details

.parse(blob) ⇒ Object

Parse



40
41
42
43
44
# File 'lib/carps/mod/answers.rb', line 40

def Answers.parse blob
   yaml, blob = find K.answers, blob
   answers = YAML::load yaml
   [Answers.new(answers), blob]
end

Instance Method Details

#answer(question, response) ⇒ Object

Set an answer to a question



52
53
54
# File 'lib/carps/mod/answers.rb', line 52

def answer question, response
   @answers[question] = response
end

#displayObject

Display answers



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/carps/mod/answers.rb', line 57

def display
   if @answers.empty?
      UI::highlight "#{from} did not return any answers."
   else
      UI::highlight "#{from}'s answers:"
      h = HighLine.new
      @answers.each do |que, ans|
         puts ""
         puts h.color(que, :green)
         ans.each_line do |ln|
            puts ">  " + ln
         end
      end
      puts ""
   end
end

#emitObject

Emit



47
48
49
# File 'lib/carps/mod/answers.rb', line 47

def emit
   V.answers @answers.to_yaml
end