Sha256: 74124c45e6999e95e9d4cad73ab19f4a4aba0e8fea2befe4d4826ecf6d6045a1

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module MassiveSitemap
  module Writer
    class Base
      OPTS = {}

      attr_reader :options

      def initialize(options = {})
        @options = self.class::OPTS.merge(options)
        @stream  = nil
      end

      # API
      def init!(options = {})
        close!
        @options.merge!(options)
        if init?
          @stream = open_stream
        end
      end

      def close!
        if inited?
          close_stream(@stream)
          @stream = nil
        end
      end

      def inited?
        @stream
      end

      def print(string)
        @stream.print(string) if inited?
      end

      def each(&block)
        streams.each(&block)
      end

      def current
        stream
      end

      # def flush!
      #  @streams = []
      # end

      # Interface
      protected
      def open_stream
        @string ||= StringIO.new
      end

      def close_stream(stream)
      end

      def init?
        true
      end

      def streams
        @streams ||= []
      end

      def stream
        nil
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
massive_sitemap-2.0.0.rc4 lib/massive_sitemap/writer/base.rb