Module: Inform::History

Defined in:
lib/runtime/history.rb

Overview

The History module

Constant Summary collapse

DefaultHistoryLimit =
10
Histories =
defined?(Java) ? java.util.concurrent.ConcurrentHashMap.new : {}
HistoryCommandPattern =
%r{^(!|history)$}.freeze

Instance Method Summary collapse

Instance Method Details

#historyObject



29
30
31
# File 'lib/runtime/history.rb', line 29

def history
  Histories[@player.identity] ||= []
end

#history_limitObject



33
34
35
36
# File 'lib/runtime/history.rb', line 33

def history_limit
  return DefaultHistoryLimit unless @player.respond_to?(:preferences)
  @player.preferences.|(:history_limit, DefaultHistoryLimit).to_i
end

#record_history(s) ⇒ Object



38
39
40
41
42
43
# File 'lib/runtime/history.rb', line 38

def record_history(s)
  return if s.nil? || s.empty? || HistoryCommandPattern.match?(s)
  history.delete_if { |i| i == s }
  history.push(s)
  history.shift if history.length > history_limit
end