Class: OdfThumb::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/odf_thumb/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Document

Returns a new instance of Document.



4
5
6
7
8
9
10
# File 'lib/odf_thumb/document.rb', line 4

def initialize(source)
  unless File.readable? source
    raise ArgumentError.new "Cannot read source file"
  end

  @source = source
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



2
3
4
# File 'lib/odf_thumb/document.rb', line 2

def source
  @source
end

Instance Method Details

#has_thumb?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
# File 'lib/odf_thumb/document.rb', line 12

def has_thumb?
  Zip::File.open(source) do |file|
    !!file.find_entry("Thumbnails/thumbnail.png")
  end
rescue Zip::Error
  false
end

#thumbnailObject



20
21
22
23
24
25
26
# File 'lib/odf_thumb/document.rb', line 20

def thumbnail
  Zip::File.open(source) do |file|
    file.read("Thumbnails/thumbnail.png")
  end
rescue Zip::Error, Errno::ENOENT
  nil
end

#write_thumbnail_to(target) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/odf_thumb/document.rb', line 28

def write_thumbnail_to(target)
  Zip::File.open(source) do |file|
    file.extract("Thumbnails/thumbnail.png", target)
  end
rescue Zip::Error, Errno::ENOENT
  nil
end