Class: Inform::Grammar::Index

Inherits:
Hash show all
Defined in:
lib/runtime/grammar_parser.rb

Overview

The Inform::Grammar::Index class

Constant Summary collapse

AdminPattern =
%r{admin}.freeze
BuilderPattern =
%r{builder}.freeze
Profanity =
%w[shit damn fuck sod].freeze
ValidModes =
i[admin builder player].freeze
ModePatterns =
ValidModes.each_with_object({}) { |key, memo| memo[key] = Regexp.new(key.to_s) }

Constants inherited from Hash

Hash::Empty, Hash::MethodBooleanPattern, Hash::MethodWriterPattern

Instance Method Summary collapse

Methods inherited from Hash

#sort

Instance Method Details

#all(actor = nil, grammar_index = self) ⇒ Object



293
294
295
296
297
298
# File 'lib/runtime/grammar_parser.rb', line 293

def all(actor = nil, grammar_index = self)
  return grammar_index.map(&:keys).flatten.sort if actor.nil?
  mode = role(actor)
  init_all_verbs_by_mode(mode, grammar_index, actor) unless Inform::Grammar.partitions.include?(mode)
  Inform::Grammar.partitions[mode]
end

#by_mode(mode = nil, grammar_index = self) ⇒ Object



300
301
302
303
304
# File 'lib/runtime/grammar_parser.rb', line 300

def by_mode(mode = nil, grammar_index = self)
  mode = validate(mode)
  init_verbs_filtered_by_mode(mode, grammar_index) unless Inform::Grammar.selections.include?(mode)
  Inform::Grammar.selections[mode]
end

#lookup(key, actor = nil, grammar_index = self) ⇒ Object



284
285
286
287
288
289
290
291
# File 'lib/runtime/grammar_parser.rb', line 284

def lookup(key, actor = nil, grammar_index = self)
  return nil if key.nil? || !grammar_index.include?(key)
  verb = grammar_index[key].dup
  return verb if actor.nil?
  return nil if guarded?(verb, actor)
  filter_by_permission(verb, actor)
  verb
end