diff --git a/lib/oga.rb b/lib/oga.rb index d671571..8eee85b 100644 --- a/lib/oga.rb +++ b/lib/oga.rb @@ -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. diff --git a/lib/oga/node_name_set.rb b/lib/oga/node_name_set.rb new file mode 100644 index 0000000..3d0c57d --- /dev/null +++ b/lib/oga/node_name_set.rb @@ -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 diff --git a/lib/oga/xml/html_void_elements.rb b/lib/oga/xml/html_void_elements.rb index 2efbb6f..c0ee4d1 100644 --- a/lib/oga/xml/html_void_elements.rb +++ b/lib/oga/xml/html_void_elements.rb @@ -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 diff --git a/spec/oga/node_name_set_spec.rb b/spec/oga/node_name_set_spec.rb new file mode 100644 index 0000000..ee0c374 --- /dev/null +++ b/spec/oga/node_name_set_spec.rb @@ -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