Class: GEPUB::Item
- Inherits:
-
Object
- Object
- GEPUB::Item
- Defined in:
- lib/gepub/item.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#href ⇒ Object
Returns the value of attribute href.
-
#itemid ⇒ Object
Returns the value of attribute itemid.
-
#mediatype ⇒ Object
Returns the value of attribute mediatype.
Instance Method Summary collapse
- #add_content(io) ⇒ Object
- #guess_mediatype ⇒ Object
-
#initialize(itemid, href, mediatype = nil) ⇒ Item
constructor
A new instance of Item.
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
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/gepub/item.rb', line 3 def content @content end |
#href ⇒ Object
Returns the value of attribute href.
3 4 5 |
# File 'lib/gepub/item.rb', line 3 def href @href end |
#itemid ⇒ Object
Returns the value of attribute itemid.
3 4 5 |
# File 'lib/gepub/item.rb', line 3 def itemid @itemid end |
#mediatype ⇒ Object
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_mediatype ⇒ Object
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 |