Added NodeNameSet class
This class can be used to more easily create a Set containing both lowercase and uppercase element names.
This commit is contained in:
parent
8135074a62
commit
4b21a2fadc
|
@ -7,6 +7,7 @@ require_relative 'oga/version'
|
|||
require_relative 'oga/oga'
|
||||
require_relative 'oga/lru'
|
||||
require_relative 'oga/entity_decoder'
|
||||
require_relative 'oga/node_name_set'
|
||||
|
||||
# Load these first so that the native extensions don't have to define the
|
||||
# Oga::XML namespace.
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
module Oga
|
||||
##
|
||||
# Class for storing (HTML) element names in a set and automatically adding
|
||||
# their uppercase equivalents.
|
||||
#
|
||||
class NodeNameSet < Set
|
||||
##
|
||||
# @param [Array] values
|
||||
#
|
||||
def initialize(values = [])
|
||||
values = values + values.map(&:upcase)
|
||||
|
||||
super(values)
|
||||
end
|
||||
end # NodeNameSet
|
||||
end # Oga
|
|
@ -4,9 +4,9 @@ module Oga
|
|||
# Names of the HTML void elements that should be handled when HTML lexing
|
||||
# is enabled.
|
||||
#
|
||||
# @return [Set]
|
||||
# @return [Oga::NodeNameSet]
|
||||
#
|
||||
HTML_VOID_ELEMENTS = Set.new([
|
||||
HTML_VOID_ELEMENTS = NodeNameSet.new([
|
||||
'area',
|
||||
'base',
|
||||
'br',
|
||||
|
@ -24,7 +24,5 @@ module Oga
|
|||
'track',
|
||||
'wbr'
|
||||
])
|
||||
|
||||
HTML_VOID_ELEMENTS.merge(HTML_VOID_ELEMENTS.map { |name| name.upcase })
|
||||
end # XML
|
||||
end # Oga
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Oga::NodeNameSet do
|
||||
describe '#initialize' do
|
||||
it 'adds uppercase equivalents of the input strings' do
|
||||
set = described_class.new(%w{foo bar})
|
||||
|
||||
set.to_a.should == %w{foo bar FOO BAR}
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue