Create a basic html output, to validate that we're loading data correctly.
[quanlib.git] / cover.rb
diff --git a/cover.rb b/cover.rb
new file mode 100644 (file)
index 0000000..b88f340
--- /dev/null
+++ b/cover.rb
@@ -0,0 +1,46 @@
+
+class Cover
+  def initialize(inputStream, path, mimeType)
+    @data = inputStream.read
+    @path = path
+    @mimeType = mimeType
+  end
+
+  def inspect
+    info = []
+    if nil != @data
+      info.push('size=' + @data.length.to_s)
+    else
+      info.push('empty')
+    end
+    if nil != @path
+      info.push('path="' + @path + '"')
+    end
+    if nil != @mimeType
+      info.push('mimeType="' + @mimeType + '"')
+    end
+    return '(Cover:' + info.join(',') + ')'
+  end
+
+  def to_s
+    return inspect
+  end
+
+  def writeImage(outputDir, baseName)
+    filename = baseName + getExt()
+    open(outputDir + '/' + filename, 'wb') do |fd|
+      fd.write(@data)
+    end
+    return filename, @mimeType
+  end
+
+  protected
+  def getExt
+    pos = @path.rindex('.')
+    if nil == pos
+      return '.img'
+    end
+    return @path.slice(pos, @path.length)
+  end
+end
+