Class: Fable::ControlCommand

Inherits:
RuntimeObject show all
Defined in:
lib/fable/control_command.rb

Constant Summary collapse

COMMANDS =
{
  NOT_SET: -1,
  EVALUATION_START: "ev",
  EVALUATION_OUTPUT: "out",
  EVALUATION_END: "/ev",
  DUPLICATE_TOPMOST: "du",
  POP_EVALUATED_VALUE: "pop",
  POP_FUNCTION: "~ret",
  POP_TUNNEL: "->->",
  BEGIN_STRING_EVALUATION_MODE: "str",
  END_STRING_EVALUATION_MODE: "/str",
  NOOP: "nop",
  PUSH_CHOICE_COUNT: "choiceCnt",
  TURNS: "turn",
  TURNS_SINCE: "turns",
  READ_COUNT: "readc",
  RANDOM: "rnd",
  SEED_RANDOM: "srnd",
  VISIT_INDEX: "visit",
  SEQUENCE_SHUFFLE_INDEX: "seq",
  START_THREAD: "thread",
  DONE: "done",
  STORY_END: "end",
  LIST_FROM_INT: "listInt",
  LIST_RANGE: "range",
  LIST_RANDOM: "lrnd",

  GLUE: "<>",
}.freeze
LOOKUP =
COMMANDS.invert.freeze

Instance Attribute Summary collapse

Attributes inherited from RuntimeObject

#original_object, #own_debug_metadata, #parent, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RuntimeObject

#compact_path_string, #convert_path_to_relative, #copy, #debug_line_number_of_path, #debug_metadata, #indentation_string, #resolve_path, #root_content_container

Constructor Details

#initialize(command_symbol) ⇒ ControlCommand

Returns a new instance of ControlCommand.



46
47
48
49
# File 'lib/fable/control_command.rb', line 46

def initialize(command_symbol)
  super()
  self.command_type = LOOKUP[command_symbol]
end

Instance Attribute Details

#command_typeObject

Returns the value of attribute command_type.



35
36
37
# File 'lib/fable/control_command.rb', line 35

def command_type
  @command_type
end

Class Method Details

.begin_string_evaluation_modeObject



87
88
89
# File 'lib/fable/control_command.rb', line 87

def self.begin_string_evaluation_mode
  self.new(COMMANDS[:BEGIN_STRING_EVALUATION_MODE])
end

.doneObject



135
136
137
# File 'lib/fable/control_command.rb', line 135

def self.done
  self.new(COMMANDS[:DONE])
end

.duplicate_topmostObject



71
72
73
# File 'lib/fable/control_command.rb', line 71

def self.duplicate_topmost
  self.new(COMMANDS[:DUPLICATE_TOPMOST])
end

.end_string_evaluation_modeObject



91
92
93
# File 'lib/fable/control_command.rb', line 91

def self.end_string_evaluation_mode
  self.new(COMMANDS[:END_STRING_EVALUATION_MODE])
end

.evaluation_endObject



67
68
69
# File 'lib/fable/control_command.rb', line 67

def self.evaluation_end
  self.new(COMMANDS[:EVALUATION_END])
end

.evaluation_outputObject



63
64
65
# File 'lib/fable/control_command.rb', line 63

def self.evaluation_output
  self.new(COMMANDS[:EVALUATION_OUTPUT])
end

.evaluation_startObject



59
60
61
# File 'lib/fable/control_command.rb', line 59

def self.evaluation_start
  self.new(COMMANDS[:EVALUATION_START])
end

.get_control_command(value) ⇒ Object

Raises:

  • (ArgumentError)


41
42
43
44
# File 'lib/fable/control_command.rb', line 41

def self.get_control_command(value)
  raise ArgumentError if !is_control_command?(value)
  self.new(value)
end

.is_control_command?(value) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/fable/control_command.rb', line 37

def self.is_control_command?(value)
  LOOKUP.has_key?(value)
end

.is_instance_of?(object, command_type) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/fable/control_command.rb', line 51

def self.is_instance_of?(object, command_type)
  object.is_a?(self) && object.command_type == command_type
end

.list_from_intObject



143
144
145
# File 'lib/fable/control_command.rb', line 143

def self.list_from_int
  self.new(COMMANDS[:LIST_FROM_INT])
end

.list_randomObject



151
152
153
# File 'lib/fable/control_command.rb', line 151

def self.list_random
  self.new(COMMANDS[:LIST_RANDOM])
end

.list_rangeObject



147
148
149
# File 'lib/fable/control_command.rb', line 147

def self.list_range
  self.new(COMMANDS[:LIST_RANGE])
end

.noopObject



95
96
97
# File 'lib/fable/control_command.rb', line 95

def self.noop
  self.new(COMMANDS[:NOOP])
end

.pop_evaluated_valueObject



75
76
77
# File 'lib/fable/control_command.rb', line 75

def self.pop_evaluated_value
  self.new(COMMANDS[:POP_EVALUATED_VALUE])
end

.pop_functionObject



79
80
81
# File 'lib/fable/control_command.rb', line 79

def self.pop_function
  self.new(COMMANDS[:POP_FUNCTION])
end

.pop_tunnelObject



83
84
85
# File 'lib/fable/control_command.rb', line 83

def self.pop_tunnel
  self.new(COMMANDS[:POP_TUNNEL])
end

.push_choice_countObject



99
100
101
# File 'lib/fable/control_command.rb', line 99

def self.push_choice_count
  self.new(COMMANDS[:PUSH_CHOICE_COUNT])
end

.randomObject



115
116
117
# File 'lib/fable/control_command.rb', line 115

def self.random
  self.new(COMMANDS[:RANDOM])
end

.read_countObject



111
112
113
# File 'lib/fable/control_command.rb', line 111

def self.read_count
  self.new(COMMANDS[:READ_COUNT])
end

.seed_randomObject



119
120
121
# File 'lib/fable/control_command.rb', line 119

def self.seed_random
  self.new(COMMANDS[:SEED_RANDOM])
end

.sequence_shuffle_indexObject



127
128
129
# File 'lib/fable/control_command.rb', line 127

def self.sequence_shuffle_index
  self.new(COMMANDS[:SEQUENCE_SHUFFLE_INDEX])
end

.start_threadObject



131
132
133
# File 'lib/fable/control_command.rb', line 131

def self.start_thread
  self.new(COMMANDS[:START_THREAD])
end

.story_endObject



139
140
141
# File 'lib/fable/control_command.rb', line 139

def self.story_end
  self.new(COMMANDS[:STORY_END])
end

.turnsObject



103
104
105
# File 'lib/fable/control_command.rb', line 103

def self.turns
  self.new(COMMANDS[:TURNS])
end

.turns_sinceObject



107
108
109
# File 'lib/fable/control_command.rb', line 107

def self.turns_since
  self.new(COMMANDS[:TURNS_SINCE])
end

.visit_indexObject



123
124
125
# File 'lib/fable/control_command.rb', line 123

def self.visit_index
  self.new(COMMANDS[:VISIT_INDEX])
end

Instance Method Details

#to_sObject



55
56
57
# File 'lib/fable/control_command.rb', line 55

def to_s
  command_type.to_s
end