lib/rubiks/nodes/dimension.rb in rubiks-0.0.4 vs lib/rubiks/nodes/dimension.rb in rubiks-0.0.5

- old
+ new

@@ -35,10 +35,11 @@ def parse_hierarchies(hierarchies_array) return if hierarchies_array.nil? || hierarchies_array.empty? hierarchies_array.each do |hierarchy_hash| + hierarchy_hash['dimension'] = self.name if self.name.present? self.hierarchies << ::Rubiks::Hierarchy.new_from_hash(hierarchy_hash) end end def to_hash @@ -46,9 +47,26 @@ hash['name'] = self.name.to_s if self.name.present? hash['hierarchies'] = self.hierarchies.map(&:to_hash) if self.hierarchies.present? return hash + end + + def to_xml(builder = nil) + builder = Builder::XmlMarkup.new(:indent => 2) if builder.nil? + + attrs = self.to_hash + attrs.delete('hierarchies') + attrs['name'] = self.name.titleize if self.name.present? + attrs.keys.each do |key| + attrs[key.camelize(:lower)] = attrs.delete(key) + end + attrs['foreignKey'] = "#{self.name.underscore}_id" if self.name.present? + builder.dimension(attrs) { + self.hierarchies.each do |hier| + hier.to_xml(builder) + end if self.hierarchies.present? + } end end end