Class: Glaemscribe::API::CharsetParser
- Inherits:
-
Object
- Object
- Glaemscribe::API::CharsetParser
- Defined in:
- lib/api/charset_parser.rb
Instance Method Summary collapse
-
#initialize ⇒ CharsetParser
constructor
A new instance of CharsetParser.
- #parse(file_path) ⇒ Object
Constructor Details
#initialize ⇒ CharsetParser
Returns a new instance of CharsetParser.
28 29 30 |
# File 'lib/api/charset_parser.rb', line 28 def initialize() @charset = nil end |
Instance Method Details
#parse(file_path) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/api/charset_parser.rb', line 32 def parse(file_path) @charset = Charset.new(ResourceManager::charset_name_from_file_path(file_path)) raw = File.open(file_path,"rb:utf-8").read doc = Glaeml::Parser.new.parse(raw) if(doc.errors.any?) @charset.errors = doc.errors return @charset end doc.root_node.gpath("char").each { |char_element| code = char_element.args[0].hex names = char_element.args[1..-1].map{|cname| cname.strip }.reject{ |cname| cname.empty? } @charset.add_char(char_element.line,code,names) } @charset.finalize @charset end |