Class: Linguistics::Latin::Util::LatinIRB

Inherits:
Object
  • Object
show all
Defined in:
lib/LatinIRB.rb,
lib/latinirb/version.rb

Constant Summary collapse

VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.beginObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/LatinIRB.rb', line 11

def self.begin
  configure_irb_singleton
  @irb = get_irb_singleton
  set_required_main_irb_context
  configure_latinverb_prompt
  print_prelude

  trap("SIGINT") do
    irb.signal_handle
  end

  begin
    catch(:IRB_EXIT) do
      # Start the REPL
      @irb.eval_input
    end
  end

  puts "Vale!  Come back to LatinIRB soon."
end

.configure_irb_singletonObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/LatinIRB.rb', line 45

def self.configure_irb_singleton
  IRB.setup(nil)
  @CONF = IRB.conf

  # This will be the script IRB sources on execution. You can
  # pre-define variables (@aFirst, etc.) and convenience methods here.

  @CONF[:SCRIPT]=File.join(File.dirname(__FILE__),  %w|latirb.rb|)

  # No, do not tell me what you read in
  @CONF[:ECHO]=false

  # Nor tell me how it evaluated
  @CONF[:VERBOSE]=false
end

.configure_latinverb_promptObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/LatinIRB.rb', line 32

def self.configure_latinverb_prompt
  # Create a LatinIRB prompt
  @CONF[:PROMPT][:LATINIRB] = {
                                :PROMPT_I    => "LatinIRB > ",
                                :PROMPT_S    => "LatinIRB%l> ",
                                :PROMPT_C    => "LatinIRB > ",
                                :PROMPT_N    => "LatinIRB ?> ",
                                :RETURN      => " => %s \n",
                                :AUTO_INDENT => true
                              }
  @CONF[:PROMPT_MODE]=:LATINIRB
end

.get_irb_singletonObject



61
62
63
64
65
66
67
68
# File 'lib/LatinIRB.rb', line 61

def self.get_irb_singleton
  # Create an irb object that is programmed to source a configuration
  # file that ends with a call to 'irb' itself after defining several
  # instance variables

  @CONF[:LOAD_MODULES]=["latinverb"]
  IRB::Irb.new(nil, @CONF[:SCRIPT])
end

.irb_ivarsObject



78
79
80
81
82
# File 'lib/LatinIRB.rb', line 78

def self.irb_ivars
  File::open(@irb.context.io.file_name).readlines.grep(/^@/).map do |x|
    x.sub(/(@\w+)\s.*\n/, "\\1")
  end
end


70
71
72
73
74
75
76
# File 'lib/LatinIRB.rb', line 70

def self.print_prelude
  puts "Beginning a LatinVerb session."
  puts "The following verbs have been made available to this session:"
  self.irb_ivars.each{|x| puts "  * #{x}"}
  puts "Tab-completion of the conjugation \"vectors\" is supported."
  puts ""
end

.set_required_main_irb_contextObject



84
85
86
87
# File 'lib/LatinIRB.rb', line 84

def self.set_required_main_irb_context
  # Unless this is set, eval_input will fail.
  @CONF[:MAIN_CONTEXT] = @irb.context
end