Class: Gemwarrior::Repl

Inherits:
Object
  • Object
show all
Defined in:
lib/gemwarrior/repl.rb

Constant Summary collapse

QUIT_MESSAGE =

CONSTANTS MESSAGES

'Temporal flux detected. Shutting down...'.colorize(:red)
SPLASH_MESSAGE =
'Welcome to the land of *Jool*, where randomized fortune is just as likely as mayhem.'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(world, evaluator) ⇒ Repl

Returns a new instance of Repl.



22
23
24
25
# File 'lib/gemwarrior/repl.rb', line 22

def initialize(world, evaluator)
  self.world  = world
  self.eval   = evaluator
end

Instance Attribute Details

#evalObject

Returns the value of attribute eval.



20
21
22
# File 'lib/gemwarrior/repl.rb', line 20

def eval
  @eval
end

#worldObject

Returns the value of attribute world.



20
21
22
# File 'lib/gemwarrior/repl.rb', line 20

def world
  @world
end

Instance Method Details

#start(initialCommand = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gemwarrior/repl.rb', line 27

def start(initialCommand = nil)
  setup_screen(initialCommand)

  clocker = Clocker.new

  at_exit do
    pl = world.player
    duration = clocker.stop
    print_stats(duration, pl)
  end

  clocker.clock {
    # main loop
    loop do
      prompt
      begin
        input = read_line
        result = eval.evaluate(input)
        if result.eql?("exit")
          exit
        else
          puts result
        end
      rescue Interrupt
        puts
        puts QUIT_MESSAGE
        exit
      end
    end
  }
end