Class: GEPUB::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/gepub/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(itemid, href, mediatype = nil) ⇒ Item

Returns a new instance of Item.



5
6
7
8
9
# File 'lib/gepub/item.rb', line 5

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

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/gepub/item.rb', line 3

def content
  @content
end

#hrefObject

Returns the value of attribute href.



3
4
5
# File 'lib/gepub/item.rb', line 3

def href
  @href
end

#itemidObject

Returns the value of attribute itemid.



3
4
5
# File 'lib/gepub/item.rb', line 3

def itemid
  @itemid
end

#mediatypeObject

Returns the value of attribute mediatype.



3
4
5
# File 'lib/gepub/item.rb', line 3

def mediatype
  @mediatype
end

Instance Method Details

#add_content(io) ⇒ Object



11
12
13
14
15
# File 'lib/gepub/item.rb', line 11

def add_content(io)
  io.binmode
  @content = io.read
  self
end

#guess_mediatypeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gepub/item.rb', line 17

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