Class: Glaemscribe::API::Charset::VirtualChar
- Defined in:
- lib/api/charset.rb
Overview
Could have had inheritance here …
Defined Under Namespace
Classes: VirtualClass
Instance Attribute Summary collapse
-
#charset ⇒ Object
Returns the value of attribute charset.
-
#classes ⇒ Object
Returns the value of attribute classes.
-
#default ⇒ Object
Returns the value of attribute default.
-
#line ⇒ Object
Returns the value of attribute line.
-
#names ⇒ Object
Returns the value of attribute names.
-
#reversed ⇒ Object
Returns the value of attribute reversed.
Instance Method Summary collapse
- #[](trigger_char_name) ⇒ Object
- #finalize ⇒ Object
-
#initialize ⇒ VirtualChar
constructor
A new instance of VirtualChar.
- #sequence? ⇒ Boolean
- #str ⇒ Object
- #virtual? ⇒ Boolean
Constructor Details
#initialize ⇒ VirtualChar
Returns a new instance of VirtualChar.
106 107 108 109 110 111 |
# File 'lib/api/charset.rb', line 106 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
#charset ⇒ Object
Returns the value of attribute charset.
97 98 99 |
# File 'lib/api/charset.rb', line 97 def charset @charset end |
#classes ⇒ Object
Returns the value of attribute classes.
96 97 98 |
# File 'lib/api/charset.rb', line 96 def classes @classes end |
#default ⇒ Object
Returns the value of attribute default.
99 100 101 |
# File 'lib/api/charset.rb', line 99 def default @default end |
#line ⇒ Object
Returns the value of attribute line.
94 95 96 |
# File 'lib/api/charset.rb', line 94 def line @line end |
#names ⇒ Object
Returns the value of attribute names.
95 96 97 |
# File 'lib/api/charset.rb', line 95 def names @names end |
#reversed ⇒ Object
Returns the value of attribute reversed.
98 99 100 |
# File 'lib/api/charset.rb', line 98 def reversed @reversed end |
Instance Method Details
#[](trigger_char_name) ⇒ Object
162 163 164 |
# File 'lib/api/charset.rb', line 162 def [](trigger_char_name) @lookup_table[trigger_char_name] end |
#finalize ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/api/charset.rb', line 123 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
170 171 172 |
# File 'lib/api/charset.rb', line 170 def sequence? false end |
#str ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/api/charset.rb', line 113 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
166 167 168 |
# File 'lib/api/charset.rb', line 166 def virtual? true end |