Class: Glaemscribe::API::Charset
- Inherits:
-
Object
- Object
- Glaemscribe::API::Charset
- Defined in:
- lib/api/charset.rb
Defined Under Namespace
Classes: Char
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.
Instance Method Summary collapse
- #[](symbol) ⇒ Object
-
#add_char(line, code, names) ⇒ Object
Pass integer (utf8 num) and array (of strings).
- #finalize ⇒ Object
-
#initialize(name) ⇒ Charset
constructor
A new instance of Charset.
Constructor Details
#initialize(name) ⇒ Charset
Returns a new instance of Charset.
42 43 44 45 46 |
# File 'lib/api/charset.rb', line 42 def initialize(name) @name = name @chars = [] @errors = [] 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 |
Instance Method Details
#[](symbol) ⇒ Object
78 79 80 |
# File 'lib/api/charset.rb', line 78 def [](symbol) @lookup_table[symbol] end |
#add_char(line, code, names) ⇒ Object
Pass integer (utf8 num) and array (of strings)
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/api/charset.rb', line 49 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') @chars << c end |
#finalize ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/api/charset.rb', line 60 def finalize @errors = [] @lookup_table = {} @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 } } API::Debug::log("Finalized charset '#{@name}', #{@lookup_table.count} symbols loaded.") end |