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

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

Overview

Could have had inheritance here …

Defined Under Namespace

Classes: VirtualClass

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVirtualChar

Returns a new instance of VirtualChar.



65
66
67
68
69
70
# File 'lib/api/charset.rb', line 65

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

Instance Attribute Details

#charsetObject

Returns the value of attribute charset.



56
57
58
# File 'lib/api/charset.rb', line 56

def charset
  @charset
end

#classesObject

Returns the value of attribute classes.



55
56
57
# File 'lib/api/charset.rb', line 55

def classes
  @classes
end

#defaultObject

Returns the value of attribute default.



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

def default
  @default
end

#lineObject

Returns the value of attribute line.



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

def line
  @line
end

#namesObject

Returns the value of attribute names.



54
55
56
# File 'lib/api/charset.rb', line 54

def names
  @names
end

#reversedObject

Returns the value of attribute reversed.



57
58
59
# File 'lib/api/charset.rb', line 57

def reversed
  @reversed
end

Instance Method Details

#[](trigger_char_name) ⇒ Object



121
122
123
# File 'lib/api/charset.rb', line 121

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

#finalizeObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/api/charset.rb', line 82

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 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              
    }
  }
  if @default
    c = @charset[@default]
    if !c
      @charset.errors << Glaeml::Error.new(@line, "Default char #{@default} does not match any real character in the charset.")             
    elsif c.virtual?
      @charset.errors << Glaeml::Error.new(@line, "Default char #{@default} is virtual, it should be real only.")
    end
  end
end

#sequence?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/api/charset.rb', line 129

def sequence?
  false
end

#strObject



72
73
74
75
76
77
78
79
80
# File 'lib/api/charset.rb', line 72

def str
  
  # Will be called if the virtual char could not be replaced and still exists at the end of the transcription chain
  if @default
    @charset[@default].str
  else
    VIRTUAL_CHAR_OUTPUT
  end
end

#virtual?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/api/charset.rb', line 125

def virtual?
  true
end