Sha256: 1f9796f988d2f45d376a4eb6d379776651f57b3a8923e1a0f79d2babfcb8991e

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'epub/ocf/physical_container/zipruby'
require 'epub/ocf/physical_container/unpacked_directory'
require 'epub/ocf/physical_container/unpacked_uri'

module EPUB
  class OCF
    # @todo: Make thread save
    class PhysicalContainer
      @adapter = Zipruby

      class << self
        def adapter
          raise NoMethodError, "undefined method `#{__method__}' for #{self}" unless self == PhysicalContainer
          @adapter
        end

        def adapter=(adapter)
          raise NoMethodError, "undefined method `#{__method__}' for #{self}" unless self == PhysicalContainer
          @adapter = adapter.instance_of?(Class) ? adapter : const_get(adapter)
          adapter
        end

        def open(container_path)
          _adapter.new(container_path).open do |container|
            yield container
          end
        end

        def read(container_path, path_name)
          open(container_path) {|container|
            container.read(path_name)
          }
        end

        private

        def _adapter
          (self == PhysicalContainer) ? @adapter : self
        end
      end

      def initialize(container_path)
        @container_path = container_path
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
epub-parser-0.2.3 lib/epub/ocf/physical_container.rb