Sha256: beacd86bf94870bd6284d22bb245301c4ea0b7353d80031cd0132d0dc5a95e05

Contents?: true

Size: 785 Bytes

Versions: 11

Compression:

Stored size: 785 Bytes

Contents

module GEPUB
  class Item
    attr_accessor :itemid, :href, :mediatype, :content

    def initialize(itemid, href, mediatype = nil)
      @itemid = itemid
      @href = href
      @mediatype = mediatype || guess_mediatype
    end

    def add_content(io)
      io.binmode
      @content = io.read
      self
    end
    
    def guess_mediatype
      case File.extname(@href)
      when /.(html|xhtml)/i
        'application/xhtml+xml'
      when /.css/i
        'text/css'
      when /.(jpg|jpeg)/i
        'image/jpeg'
      when /.png/i
        'image/png'
      when /.gif/i
        'image/gif'
      when /.svg/i
        'image/svg+xml'
      when /.opf/i
        'application/oebps-package+xml'
      when /.ncx/i
        'application/x-dtbncx+xml'
      end
    end
  end
end  

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gepub-0.4.5 lib/gepub/item.rb
gepub-0.4.3 lib/gepub/item.rb
gepub-0.4.2 lib/gepub/item.rb
gepub-0.4.1 lib/gepub/item.rb
gepub-0.4.0 lib/gepub/item.rb
gepub-0.3.0 lib/gepub/item.rb
gepub-0.2.2 lib/gepub/item.rb
gepub-0.2.1 lib/gepub/item.rb
gepub-0.2.0 lib/gepub/item.rb
gepub-0.1.3 lib/gepub/item.rb
gepub-0.1.1 lib/gepub/item.rb