Class: Gamefic::Props::Output
- Inherits:
-
Object
- Object
- Gamefic::Props::Output
- 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
- #last_input ⇒ String? readonly
- #last_prompt ⇒ String? readonly
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(**data) ⇒ Output
constructor
A new instance of Output.
- #merge!(data) ⇒ Object
- #messages ⇒ String
- #options ⇒ Array<String>
- #prompt ⇒ String
- #queue ⇒ Array<String>
- #replace(data) ⇒ Object
- #scene ⇒ Hash
- #to_hash ⇒ Hash
- #to_json(_ = nil) ⇒ Object
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_input ⇒ String? (readonly)
10 11 12 |
# File 'lib/gamefic/props/output.rb', line 10 def last_input @last_input end |
#last_prompt ⇒ String? (readonly)
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 |
#messages ⇒ String
27 28 29 |
# File 'lib/gamefic/props/output.rb', line 27 def raw_data[:messages] end |
#options ⇒ Array<String>
32 33 34 |
# File 'lib/gamefic/props/output.rb', line 32 def raw_data[:options] end |
#prompt ⇒ String
48 49 50 |
# File 'lib/gamefic/props/output.rb', line 48 def prompt raw_data[:prompt] end |
#queue ⇒ Array<String>
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 |
#scene ⇒ Hash
TODO:
Should this be a concrete class?
43 44 45 |
# File 'lib/gamefic/props/output.rb', line 43 def scene raw_data[:scene] end |
#to_hash ⇒ 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 |