Skip to content

Commit

Permalink
lastmodified accepts String and DateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
skoji committed Feb 9, 2020
1 parent 5316f5c commit 82cc120
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/gepub/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module GEPUB
# returns contributors list by display-seq or defined order.
# the contributors without display-seq is appear after contributors with display-seq.
# === Book#lastmodified(date) (delegated to Metadata#lastmodified)
# set last modified date.
# set last modified date. date is a Time, DateTime or string that can be parsed by DateTime#parse.
# === Book#modified_now (delegated to Metadata#modified_now)
# set last modified date to current time.
# === Book#lastmodified (delegated to Metadata#lastmodified)
Expand Down
3 changes: 2 additions & 1 deletion lib/gepub/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,14 @@ def lastmodified(date=UNASSIGNED)
else
@lastmodified_updated = true
date ||= Time.now
date = DateTime.parse(date) if date.is_a? String
(@content_nodes['meta'] ||= []).each {
|meta|
if (meta['property'] == 'dcterms:modified')
@content_nodes['meta'].delete meta
end
}
add_metadata('meta', date.utc.strftime('%Y-%m-%dT%H:%M:%SZ'), itemclass: DateMeta)['property'] = 'dcterms:modified'
add_metadata('meta', date.to_time.utc.strftime('%Y-%m-%dT%H:%M:%SZ'), itemclass: DateMeta)['property'] = 'dcterms:modified'
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/gepub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@
end
end


it 'should generate EPUB with specified lastmodified by string' do
epubname = File.join(File.dirname(__FILE__), 'testepub.epub')
mod_time = "2010-05-05T08:10:15Z"
@book.lastmodified = mod_time
@book.generate_epub(epubname)
File.open(epubname) do |f|
parsed_book = GEPUB::Book.parse(f)
expect(parsed_book.lastmodified.content).to eq mod_time
end
end

it 'should generate parsed and generated EPUB with renewed lastmodified' do
originalfile = File.join(File.dirname(__FILE__), 'fixtures/testdata/wasteland-20120118.epub')
epubname = File.join(File.dirname(__FILE__), 'testepub.epub')
Expand Down

0 comments on commit 82cc120

Please sign in to comment.