Added Oga::EntityDecoder

This module removes some of the code duplication needed to determine
what entity decoder to use.
This commit is contained in:
Yorick Peterse committed 2015-04-07 21:18:15 +02:00
1 parent 3f6aa04e91
commit ef7f50137a
4 files changed
+54 -2

No files matched your search

+1
View File
@@ -6,6 +6,7 @@ require 'thread'
require_relative 'oga/version'
require_relative 'oga/oga'
require_relative 'oga/lru'
require_relative 'oga/entity_decoder'
# Load these first so that the native extensions don't have to define the
# Oga::XML namespace.
+21
View File
@@ -0,0 +1,21 @@
module Oga
module EntityDecoder
##
# @see [decode]
#
def self.try_decode(input, html = false)
return input ? decode(input, html) : nil
end
##
# @param [String] input
# @param [TrueClass|FalseClass] html
# @return [String]
#
def self.decode(input, html = false)
decoder = html ? HTML::Entities : XML::Entities
return decoder.decode(input)
end
end # EntityDecoder
end # Oga
+1 -2
View File
@@ -27,8 +27,7 @@ module Oga
#
def text
unless @decoded
decoder = html? ? HTML::Entities : Entities
@text = decoder.decode(@text)
@text = EntityDecoder.try_decode(@text, html?)
@decoded = true
end