Module: ROXML::InstanceMethods
- Defined in:
- lib/quickeebooks.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#to_xml(params = {}) ⇒ Object
Returns an XML object representing this object.
Instance Method Details
#to_xml(params = {}) ⇒ Object
Returns an XML object representing this object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/quickeebooks.rb', line 48 def to_xml(params = {}) params[:fields] ||= [] params.reverse_merge!(:name => self.class.tag_name, :namespace => self.class.roxml_namespace) params[:namespace] = nil if ['*', 'xmlns'].include?(params[:namespace]) node = XML.new_node([params[:namespace], params[:name]].compact.join(':')).tap do |root| refs = (self.roxml_references.present? \ ? self.roxml_references \ : self.class.roxml_attrs.map {|attr| attr.to_ref(self) }) if params[:fields].length > 0 refs.reject! { |r| !params[:fields].include?(r.name) } end refs.each do |ref| value = ref.to_xml(self) unless value.nil? ref.update_xml(root, value) end end end end |