Class: Konjak::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/konjak/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gtt: false) ⇒ Parser

Returns a new instance of Parser.



7
8
9
# File 'lib/konjak/parser.rb', line 7

def initialize(gtt: false)
  @gtt = gtt
end

Instance Attribute Details

#gttObject

Returns the value of attribute gtt.



5
6
7
# File 'lib/konjak/parser.rb', line 5

def gtt
  @gtt
end

Instance Method Details

#parse(xml) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/konjak/parser.rb', line 11

def parse(xml)
  if gtt
    # FIXME GTT's tmx store © as ©
    xml = xml.gsub(/&(#\d+|#x[0-9a-fA-F]+|[0-9a-zA-Z]+);/) { "&#{$1};" }
    # FIXME GTT's tmx store leading space(\u0020) as non-breaking space(\u00A0)
    xml = xml.gsub("\u00A0", ' ')
  end
  doc = Nokogiri::XML.parse(xml)
  Tmx.new doc
end