Class: Glaemscribe::API::Charset::VirtualChar

Inherits:
Object
  • Object
show all
Defined in:
lib/api/charset.rb

Defined Under Namespace

Classes: VirtualClass

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVirtualChar

Returns a new instance of VirtualChar.



59
60
61
62
# File 'lib/api/charset.rb', line 59

def initialize
  @classes = {} # result_char_1 => [trigger_char_1, trigger_char_2 ...] , result_char_1 => ...
  @lookup_table = {}
end

Instance Attribute Details

#charsetObject

Returns the value of attribute charset.



52
53
54
# File 'lib/api/charset.rb', line 52

def charset
  @charset
end

#classesObject

Returns the value of attribute classes.



51
52
53
# File 'lib/api/charset.rb', line 51

def classes
  @classes
end

#lineObject

Returns the value of attribute line.



49
50
51
# File 'lib/api/charset.rb', line 49

def line
  @line
end

#namesObject

Returns the value of attribute names.



50
51
52
# File 'lib/api/charset.rb', line 50

def names
  @names
end

Instance Method Details

#[](trigger_char_name) ⇒ Object



101
102
103
# File 'lib/api/charset.rb', line 101

def [](trigger_char_name)
  @lookup_table[trigger_char_name]
end

#finalizeObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/api/charset.rb', line 68

def finalize
  @lookup_table = {}
  @classes.each{ |vc|
    
    result_char   = vc.target
    trigger_chars = vc.triggers
    
    trigger_chars.each{ |trigger_char|
      found = @lookup_table[trigger_char]
      if found
        @charset.errors << Glaeml::Error.new(@line, "Trigger char #{trigger_char} found twice in virtual char.")
      else
        rc = @charset[result_char]
        tc = @charset[trigger_char]

        if rc.nil?
          @charset.errors << Glaeml::Error.new(@line, "Trigger char #{trigger_char} points to unknown result char #{result_char}.")
        elsif tc.nil?
          @charset.errors << Glaeml::Error.new(@line, "Unknown trigger char #{trigger_char}.")
        elsif tc.class == VirtualChar
          @charset.errors << Glaeml::Error.new(@line, "Trigger char #{trigger_char} is virtual. This is not supported!")    
        elsif rc.class == VirtualChar
          @charset.errors << Glaeml::Error.new(@line, "Trigger char #{trigger_char} points to another virtual char #{result_char}. This is not supported!")
        else
          tc.names.each{|trigger_char_name| # Don't forget to match all name variants for that trigger char!
            @lookup_table[trigger_char_name] = rc
          }              
        end  
      end              
    }
  }
end

#strObject



64
65
66
# File 'lib/api/charset.rb', line 64

def str
  VIRTUAL_CHAR_OUTPUT
end

#virtual?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/api/charset.rb', line 105

def virtual?
  true
end