Sha256: 6dfbdc4eebc34c5040c733e5323fd20c9e91b8727bb1a273f1bd68e0929f4fb8

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

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

module EPUB
  class OCF
    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

2 entries across 2 versions & 1 rubygems

Version Path
epub-parser-0.2.2 lib/epub/ocf/physical_container.rb
epub-parser-0.2.1 lib/epub/ocf/physical_container.rb