Sha256: 17ddaa36f9e6014c76a73a0f1d37d1793f02a560485d7f7b89101e7fc67b94aa

Contents?: true

Size: 882 Bytes

Versions: 9

Compression:

Stored size: 882 Bytes

Contents

module Pump
  class Xml
    class Node
      attr_reader :name, :attributes, :nodes, :options

      def initialize(name, attributes={}, nodes=[], options={})
        @name       = name
        @attributes = attributes || {}
        @options    = (options || {}).dup
        @nodes      = []
        Array(nodes).each{|node| add_node(node) }
      end

      def to_s
      end

      def level=(new_level)
        @level = new_level
        nodes.each{|node| node.level = @level + 1}
      end

      private

      def add_node(node)
        node.level = level + 1
        node.options[:extra_indent] = options[:extra_indent]
        nodes << node
      end

      def level
        @level || options[:level] || 0
      end

      def tabs
        " " * ((level + extra_indent) * 2)
      end

      def extra_indent
        options[:extra_indent] || 0
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pump-0.6.0 lib/pump/xml/node.rb
pump-0.5.1 lib/pump/xml/node.rb
pump-0.5.0 lib/pump/xml/node.rb
pump-0.4.0 lib/pump/xml/node.rb
pump-0.3.0 lib/pump/xml/node.rb
pump-0.2.0 lib/pump/xml/node.rb
pump-0.1.0 lib/pump/xml/node.rb
pump-0.0.5 lib/pump/xml/node.rb
pump-0.0.4 lib/pump/xml/node.rb