File: session.rb

package info (click to toggle)
prime 1.0.0.1-2.2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,420 kB
  • sloc: ruby: 7,139; lisp: 1,866; sh: 442; makefile: 242
file content (89 lines) | stat: -rw-r--r-- 1,977 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# session.rb:
# $Id: session.rb,v 1.8 2005/03/07 07:51:32 komatsu Exp $
#
# Copyright (C) 2005 Hiroyuki Komatsu <komatsu@taiyaki.org>
#     All rights reserved.
#     This is free software with ABSOLUTELY NO WARRANTY.
#
# You can redistribute it and/or modify it under the terms of 
# the GNU General Public License version 2.

class PrimeSession
  @@engine_cache = {}

  def initialize (name, engine_classes)
    @name           = name
    @language       = ""
    @engine_classes = engine_classes
    @composer       = initialize_composer()
    @engines        = initialize_engines(engine_classes)
    @conversions    = PrimeConversionList.new()
    @context        = nil
  end

  def initialize_engines (engine_classes)
    engines = engine_classes.map { | engine_class |
      if @@engine_cache.has_key?( engine_class ) then
        @@engine_cache[ engine_class ]
      else
        @@engine_cache[ engine_class ] = eval( engine_class.to_s ).new()
      end        
    }

    def engines.command (method, *args)
      self.map {|engine|
        engine.send(method, *args)
      }
    end

    return engines
  end

  def initialize_composer ()
    composer = SuikyoComposer.new()
    return composer
  end

  def session_get_env (variable)
    case variable
    when "language" then
      return @language
    else
      return nil
    end
  end

  def set_conversions (conversions)
    @conversions = conversions
  end

  def set_selection (index_no)
    @conversions.set_conversion_index(index_no)
    return @conversions[index_no]
  end
  def get_selection ()
    return @conversions.get_conversion()
  end

  def set_context (context)
    @context = context
  end
  def get_context ()
    return @context
  end

  ##
  ## Context methods
  ##
  def context_reset ()
    set_context("")
  end

  def context_set_previous_segment (segment)
    context_set_previous_word( segment.get_base() )
  end

  def context_set_previous_word (word)
    set_context(word)
  end
end