Removed lazy way of setting instance variables.
This process is quite a bit slower compared to setting instance variables directly.
This commit is contained in:
parent
043ea9a366
commit
f4b9bbd4ac
|
|
@ -38,9 +38,11 @@ module Oga
|
||||||
# @option options [String] :system_id
|
# @option options [String] :system_id
|
||||||
#
|
#
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
options.each do |key, value|
|
@name = options[:name]
|
||||||
instance_variable_set("@#{key}", value) if respond_to?(key)
|
@type = options[:type]
|
||||||
end
|
@public_id = options[:public_id]
|
||||||
|
@system_id = options[:system_id]
|
||||||
|
@inline_rules = options[:inline_rules]
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,9 @@ module Oga
|
||||||
# @option options [Oga::XML::XmlDeclaration] :xml_declaration
|
# @option options [Oga::XML::XmlDeclaration] :xml_declaration
|
||||||
#
|
#
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
options.each do |key, value|
|
@children = options[:children] || []
|
||||||
instance_variable_set("@#{key}", value) if respond_to?(key)
|
@doctype = options[:doctype]
|
||||||
end
|
@xml_declaration = options[:xml_declaration]
|
||||||
|
|
||||||
@children ||= []
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,19 @@ module Oga
|
||||||
class Element < Node
|
class Element < Node
|
||||||
attr_accessor :name, :namespace, :attributes
|
attr_accessor :name, :namespace, :attributes
|
||||||
|
|
||||||
def after_initialize
|
##
|
||||||
@attributes ||= {}
|
# @param [Hash] options
|
||||||
|
#
|
||||||
|
# @option options [String] :name The name of the element.
|
||||||
|
# @option options [String] :namespace The namespace of the element.
|
||||||
|
# @option options [Hash] :attributes The attributes of the element.
|
||||||
|
#
|
||||||
|
def initialize(options = {})
|
||||||
|
super
|
||||||
|
|
||||||
|
@name = options[:name]
|
||||||
|
@namespace = options[:namespace]
|
||||||
|
@attributes = options[:attributes] || {}
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,10 @@ module Oga
|
||||||
# @option options [Oga::XML::Node] :previous The previous node.
|
# @option options [Oga::XML::Node] :previous The previous node.
|
||||||
#
|
#
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
options.each do |key, value|
|
@parent = options[:parent]
|
||||||
instance_variable_set("@#{key}", value) if respond_to?(key)
|
@children = options[:children] || []
|
||||||
end
|
@next = options[:next]
|
||||||
|
@previous = options[:previous]
|
||||||
@children ||= []
|
|
||||||
|
|
||||||
after_initialize if respond_to?(:after_initialize)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,17 @@ module Oga
|
||||||
class Text < Node
|
class Text < Node
|
||||||
attr_accessor :text
|
attr_accessor :text
|
||||||
|
|
||||||
|
##
|
||||||
|
# @param [Hash] options
|
||||||
|
#
|
||||||
|
# @option options [String] :text The text of the node.
|
||||||
|
#
|
||||||
|
def initialize(options = {})
|
||||||
|
super
|
||||||
|
|
||||||
|
@text = options[:text]
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# @return [String]
|
# @return [String]
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,9 @@ module Oga
|
||||||
# @option options [String] :standalone
|
# @option options [String] :standalone
|
||||||
#
|
#
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
options.each do |key, value|
|
@version = options[:version] || '1.0'
|
||||||
instance_variable_set("@#{key}", value) if respond_to?(key)
|
@encoding = options[:encoding] || 'UTF-8'
|
||||||
end
|
@standalone = options[:standalone]
|
||||||
|
|
||||||
@version ||= '1.0'
|
|
||||||
@encoding ||= 'UTF-8'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue