Sha256: 7a4329d7703d96ad733a36ac1c88c1b2ccdd9df4b449a634c97c625bf2492d28

Contents?: true

Size: 904 Bytes

Versions: 3

Compression:

Stored size: 904 Bytes

Contents

module MassiveSitemap
  module Writer
    class Base
      OPTS = {}

      attr_reader :options

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

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

      def close_stream(stream)
      end

      def init?
        true
      end

      def streams
        []
      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
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
massive_sitemap-2.0.0.rc3 lib/massive_sitemap/writer/base.rb
massive_sitemap-2.0.0.rc2 lib/massive_sitemap/writer/base.rb
massive_sitemap-2.0.0.rc1 lib/massive_sitemap/writer/base.rb