Sha256: 0b09e56b91cbf99b9920a9e090c169c898d629911e1948573e0f07f2aeee0dca

Contents?: true

Size: 1.51 KB

Versions: 26

Compression:

Stored size: 1.51 KB

Contents

module EPUB
  module Publication
    class Package
      class Guide
        include Inspector::PublicationModel
        attr_accessor :package, :references

        def initialize
          Reference::TYPES.each do |type|
            variable_name = '@' + type.gsub('-', '_')
            instance_variable_set variable_name, nil
          end
          @references = []
        end

        def <<(reference)
          reference.guide = self
          references << reference
        end

        class Reference
          TYPES = %w[cover title-page toc index glossary acknowledgements bibliography colophon copyright-page dedication epigraph foreword loi lot notes preface text]
          attr_accessor :guide,
                        :type, :title
          attr_reader :href

          def href=(iri)
            @href = iri.kind_of?(Addressable::URI) ? iri : Addressable::URI.parse(iri)
          end

          def item
            return @item if @item

            request_uri = href.request_uri
            @item = @guide.package.manifest.items.find {|item|
              item.href.request_uri == request_uri
            }
          end
        end

        Reference::TYPES.each do |type|
          method_name = type.gsub('-', '_')
          define_method method_name do
            var = instance_variable_get "@#{method_name}"
            return var if var

            var = references.find {|ref| ref.type == type}
            instance_variable_set "@#{method_name}", var
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
epub-parser-0.4.8 lib/epub/publication/package/guide.rb
epub-parser-0.4.7 lib/epub/publication/package/guide.rb
epub-parser-0.4.6 lib/epub/publication/package/guide.rb
epub-parser-0.4.5 lib/epub/publication/package/guide.rb
epub-parser-0.4.4 lib/epub/publication/package/guide.rb
epub-parser-0.4.3 lib/epub/publication/package/guide.rb
epub-parser-0.4.2 lib/epub/publication/package/guide.rb
epub-parser-0.4.1 lib/epub/publication/package/guide.rb
epub-parser-0.4.0 lib/epub/publication/package/guide.rb
epub-parser-0.3.9 lib/epub/publication/package/guide.rb
epub-parser-0.3.8 lib/epub/publication/package/guide.rb
epub-parser-0.3.7 lib/epub/publication/package/guide.rb
epub-parser-0.3.6 lib/epub/publication/package/guide.rb
epub-parser-0.3.5 lib/epub/publication/package/guide.rb
epub-parser-0.3.4 lib/epub/publication/package/guide.rb
epub-parser-0.3.3 lib/epub/publication/package/guide.rb
epub-parser-0.3.2 lib/epub/publication/package/guide.rb
epub-parser-0.3.1 lib/epub/publication/package/guide.rb
epub-parser-0.3.0 lib/epub/publication/package/guide.rb
epub-parser-0.2.9 lib/epub/publication/package/guide.rb