lib/mondrian/olap/schema_element.rb in mondrian-olap-0.2.0 vs lib/mondrian/olap/schema_element.rb in mondrian-olap-0.3.0
- old
+ new
@@ -19,10 +19,11 @@
end
@attributes.merge!(attributes)
self.class.elements.each do |element|
instance_variable_set("@#{pluralize(element)}", [])
end
+ @xml_fragments = []
instance_eval &block if block
end
def self.attributes(*names)
names.each do |name|
@@ -65,10 +66,18 @@
def self.content(type=nil)
return @content if type.nil?
@content = type
end
+ attr_reader :xml_fragments
+ def xml(string)
+ string = string.strip
+ fragment = Nokogiri::XML::DocumentFragment.parse(string)
+ raise ArgumentError, "Invalid XML fragment:\n#{string}" if fragment.children.empty?
+ @xml_fragments << string
+ end
+
def to_xml(options={})
options[:upcase_data_dictionary] = @upcase_data_dictionary unless @upcase_data_dictionary.nil?
Nokogiri::XML::Builder.new do |xml|
add_to_xml(xml, options)
end.to_xml
@@ -81,9 +90,12 @@
xml.send(tag_name(self.class.name), @content, xmlized_attributes(options))
else
xml.send(tag_name(self.class.name), xmlized_attributes(options)) do
self.class.elements.each do |element|
instance_variable_get("@#{pluralize(element)}").each {|item| item.add_to_xml(xml, options)}
+ end
+ @xml_fragments.each do |xml_fragment|
+ xml.send(:insert, Nokogiri::XML::DocumentFragment.parse(xml_fragment))
end
end
end
end