Sha256: 94636a6e93aba8e15fd389741a0eb4da639f989e5cb026e3c180c9306b4116b7

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

module EPUB
  module Inspector
    INSTANCE_VARIABLES_OPTION = {:exclude => []}
    SIMPLE_TEMPLATE = "#<%{class}:%{object_id}>"

    def inspect_simply
      SIMPLE_TEMPLATE % {
        :class => self.class,
        :object_id => inspect_object_id
      }
    end

    def inspect_object_id
      (__id__ << 1).to_s(16)
    end

    def inspect_instance_variables(options={})
      options = INSTANCE_VARIABLES_OPTION.merge(options)
      exclude = options[:exclude]

      (instance_variables - exclude).map {|name|
        value = instance_variable_get(name)
        "#{name}=#{value.inspect}"
      }.join(' ')
    end

    module PublicationModel
      TEMPLATE = "#<%{class}:%{object_id} @package=%{package} %{attributes}>"
      class << self
        def included(mod)
          mod.__send__ :include, Inspector
        end
      end

      def inspect
        TEMPLATE % {
          :class      => self.class,
          :package    => package.inspect_simply,
          :object_id  => inspect_object_id,
          :attributes => inspect_instance_variables(exclude: [:@package])
        }
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
epub-parser-0.2.5 lib/epub/inspector.rb
epub-parser-0.2.4 lib/epub/inspector.rb
epub-parser-0.2.3 lib/epub/inspector.rb
epub-parser-0.2.2 lib/epub/inspector.rb
epub-parser-0.2.1 lib/epub/inspector.rb
epub-parser-0.2.0 lib/epub/inspector.rb
epub-parser-0.1.9 lib/epub/inspector.rb
epub-parser-0.1.8 lib/epub/inspector.rb
epub-parser-0.1.7.1 lib/epub/inspector.rb
epub-parser-0.1.7 lib/epub/inspector.rb
epub-parser-io-0.1.6b lib/epub/inspector.rb
epub-parser-io-0.1.6a lib/epub/inspector.rb
epub-parser-io-0.1.6 lib/epub/inspector.rb
epub-parser-0.1.6 lib/epub/inspector.rb