Class: Gamefic::Props::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/props/output.rb

Overview

A container for output sent to players with a hash interface for custom data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**data) ⇒ Output

Returns a new instance of Output.



15
16
17
18
19
20
21
22
23
24
# File 'lib/gamefic/props/output.rb', line 15

def initialize **data
  @raw_data = {
    messages: '',
    options: [],
    queue: [],
    scene: {},
    prompt: ''
  }
  merge! data
end

Instance Attribute Details

#last_inputString? (readonly)

Returns:



10
11
12
# File 'lib/gamefic/props/output.rb', line 10

def last_input
  @last_input
end

#last_promptString? (readonly)

Returns:



13
14
15
# File 'lib/gamefic/props/output.rb', line 13

def last_prompt
  @last_prompt
end

Instance Method Details

#[](key) ⇒ Object



52
53
54
# File 'lib/gamefic/props/output.rb', line 52

def [] key
  raw_data[key]
end

#[]=(key, value) ⇒ Object



56
57
58
# File 'lib/gamefic/props/output.rb', line 56

def []= key, value
  raw_data[key] = value
end

#merge!(data) ⇒ Object



69
70
71
# File 'lib/gamefic/props/output.rb', line 69

def merge! data
  data.each { |key, val| self[key] = val }
end

#messagesString

Returns:



27
28
29
# File 'lib/gamefic/props/output.rb', line 27

def messages
  raw_data[:messages]
end

#optionsArray<String>

Returns:



32
33
34
# File 'lib/gamefic/props/output.rb', line 32

def options
  raw_data[:options]
end

#promptString

Returns:



48
49
50
# File 'lib/gamefic/props/output.rb', line 48

def prompt
  raw_data[:prompt]
end

#queueArray<String>

Returns:



37
38
39
# File 'lib/gamefic/props/output.rb', line 37

def queue
  raw_data[:queue]
end

#replace(data) ⇒ Object



73
74
75
# File 'lib/gamefic/props/output.rb', line 73

def replace data
  raw_data.replace data
end

#sceneHash

TODO:

Should this be a concrete class?

Returns:

  • (Hash)


43
44
45
# File 'lib/gamefic/props/output.rb', line 43

def scene
  raw_data[:scene]
end

#to_hashHash

Returns:

  • (Hash)


61
62
63
# File 'lib/gamefic/props/output.rb', line 61

def to_hash
  raw_data.dup
end

#to_json(_ = nil) ⇒ Object



65
66
67
# File 'lib/gamefic/props/output.rb', line 65

def to_json _ = nil
  raw_data.to_json
end