Commit 08f62e61 authored by meskio's avatar meskio

Add some metadata

parent 282d8f0d
......@@ -26,9 +26,8 @@ const (
)
type Book interface {
//TODO
// Title() *string
// Author() *string
Title() string
Authors() []string
Elements() Content
NextSection() bool
PrevSection() bool
......
......@@ -21,6 +21,11 @@ import (
. "git.gitorious.org/go-pkg/epubgo.git"
)
const (
title = "title"
authors = "creator"
)
type EpubBook struct {
f *Epub
it *SpineIterator
......@@ -36,7 +41,21 @@ func NewEpubBook(path string) (b EpubBook, err error) {
return
}
//TODO: metadata
func (b EpubBook) Title() string {
t, err := b.f.Metadata(title)
if err != nil || len(t) == 0 {
return ""
}
return t[0]
}
func (b EpubBook) Authors() []string {
a, err := b.f.Metadata(authors)
if err != nil {
return nil
}
return a
}
func (b EpubBook) Elements() Content {
reader, err := b.it.Open()
......
......@@ -21,6 +21,8 @@ import "testing"
const (
book_path = "testdata/Cory_Doctorow_-_Little_Brother.epub"
book_title = "Little Brother"
book_author = "Doctorow, Cory"
)
func TestEpubBook(t *testing.T) {
......@@ -48,3 +50,17 @@ func TestEpubBook(t *testing.T) {
t.Errorf("It's not the first section")
}
}
func TestEpubBookTitle(t *testing.T) {
e, _ := NewEpubBook(book_path)
if e.Title() != book_title {
t.Errorf("Not valid title: %v", e.Title())
}
}
func TestEpubBookAuthor(t *testing.T) {
e, _ := NewEpubBook(book_path)
if e.Authors()[0] != book_author {
t.Errorf("Not valid author: %v", e.Authors()[0])
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment