X-Git-Url: http://jaekl.net/gitweb/?p=quanlib.git;a=blobdiff_plain;f=book.rb;h=f1481f0c7ef5cb6e96b72615a2b50f30ff044b0d;hp=03a5f259beb0005d4250bd7988edab21729ba41d;hb=b31122c5ed23e2e77b527c0979b6355e9e3dda1f;hpb=4b53af822cda819dd82d0d3e7ed066c2966ae4bf diff --git a/book.rb b/book.rb index 03a5f25..f1481f0 100644 --- a/book.rb +++ b/book.rb @@ -4,16 +4,18 @@ require 'zip' require 'author' require 'cover' +require 'store' class Book @@DC_NS_URL = 'http://purl.org/dc/elements/1.1/' - def initialize + def initialize(store) @author = nil @cover = nil @description = nil @path = nil - @series = nil + @series_id = nil + @store = store @title = nil @volume = nil end @@ -42,14 +44,26 @@ class Book return @author end + def author=(value) + @author = value + end + def cover return @cover end + def cover=(value) + @cover = value + end + def description @description end + def description=(value) + @description = value + end + def heading result = [] @@ -63,8 +77,9 @@ class Book end seriesInfo = [] - if nil != @series - seriesInfo.push(@series.to_s) + series = @store.load_series(@series_id) + if nil != series + seriesInfo.push(series.to_s) end if nil != @volume seriesInfo.push(@volume.to_s) @@ -81,8 +96,8 @@ class Book if nil != @author data.push('author="' + @author.inspect + '"') end - if nil != @series - data.push('series="' + @series + '"') + if nil != @series_id + data.push('series_id="' + @series_id.to_s() + '"') end if nil != @volume data.push('volume="' + @volume + '"') @@ -103,8 +118,16 @@ class Book @path end - def series - @series + def path=(value) + @path = value + end + + def series_id + @series_id + end + + def series_id=(value) + @series_id = value end def to_s @@ -115,10 +138,18 @@ class Book @title end + def title=(value) + @title = value + end + def volume @volume end + def volume=(value) + @volume = value + end + protected def isUpper?(c) return /[[:upper:]]/.match(c) @@ -175,12 +206,13 @@ class Book protected def parseFileName!(fileName) parts = fileName.split('/') - (@series, @volume, @title) = processTitle(parts[-1]) + (series_code, @volume, @title) = processTitle(parts[-1]) if parts.length > 1 grouping = parts[-2] reading_order = massage_author(grouping) sort_order = nil @author = Author.new(grouping, reading_order, sort_order) + @series_id = @store.get_series(grouping, series_code) end if fileName.downcase.end_with?(".epub") @@ -274,7 +306,8 @@ class Book content = m['content'] if 'calibre:series' == name - @series = content + # TODO: Dynamically create a new series? + # @series_id = content elsif 'calibre:series-index' == name @volume = content elsif 'cover' == name @@ -286,11 +319,11 @@ class Book #--------------- # Load the cover - @cover = loadCover(zipfile, opfPath, opfDoc, coverId) + @cover = load_cover(zipfile, opfPath, opfDoc, coverId) end protected - def loadCover(zipfile, opfPath, opfDoc, coverId) + def load_cover(zipfile, opfPath, opfDoc, coverId) coverFile = nil if nil == coverId coverId = "cover-image"