Class: Glaemscribe::API::Charset
- Inherits:
-
Object
- Object
- Glaemscribe::API::Charset
- Defined in:
- lib/api/charset.rb
Defined Under Namespace
Classes: Char, VirtualChar
Instance Attribute Summary collapse
-
#chars ⇒ Object
readonly
Returns the value of attribute chars.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#virtual_chars ⇒ Object
readonly
Returns the value of attribute virtual_chars.
Instance Method Summary collapse
- #[](symbol) ⇒ Object
-
#add_char(line, code, names) ⇒ Object
Pass integer (utf8 num) and array (of strings).
- #add_virtual_char(line, classes, names) ⇒ Object
- #finalize ⇒ Object
-
#initialize(name) ⇒ Charset
constructor
A new instance of Charset.
Constructor Details
#initialize(name) ⇒ Charset
Returns a new instance of Charset.
110 111 112 113 114 115 |
# File 'lib/api/charset.rb', line 110 def initialize(name) @name = name @chars = [] @errors = [] @virtual_chars = [] end |
Instance Attribute Details
#chars ⇒ Object (readonly)
Returns the value of attribute chars.
29 30 31 |
# File 'lib/api/charset.rb', line 29 def chars @chars end |
#errors ⇒ Object
Returns the value of attribute errors.
28 29 30 |
# File 'lib/api/charset.rb', line 28 def errors @errors end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/api/charset.rb', line 26 def name @name end |
#virtual_chars ⇒ Object (readonly)
Returns the value of attribute virtual_chars.
30 31 32 |
# File 'lib/api/charset.rb', line 30 def virtual_chars @virtual_chars end |
Instance Method Details
#[](symbol) ⇒ Object
167 168 169 |
# File 'lib/api/charset.rb', line 167 def [](symbol) @lookup_table[symbol] end |
#add_char(line, code, names) ⇒ Object
Pass integer (utf8 num) and array (of strings)
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/api/charset.rb', line 118 def add_char(line, code, names) return if names.empty? || names.include?("?") # Ignore characters with '?' c = Char.new c.line = line c.code = code c.names = names c.str = code.chr('UTF-8') c.charset = self @chars << c end |
#add_virtual_char(line, classes, names) ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/api/charset.rb', line 130 def add_virtual_char(line, classes, names) return if names.empty? || names.include?("?") # Ignore characters with '?' c = VirtualChar.new c.line = line c.names = names c.classes = classes # We'll check errors in finalize c.charset = self @chars << c end |
#finalize ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/api/charset.rb', line 141 def finalize @errors = [] @lookup_table = {} @virtual_chars = [] @chars.each { |c| c.names.each { |cname| found = @lookup_table[cname] if found @errors << Glaeml::Error.new(c.line, "Character #{cname} found twice.") else @lookup_table[cname] = c end } } @chars.each{ |c| if c.class == VirtualChar c.finalize @virtual_chars << c end } API::Debug::log("Finalized charset '#{@name}', #{@lookup_table.count} symbols loaded.") end |