Add this line to your application’s Gemfile:
gem 'dyck'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install dyck
Reading existing Mobi file:
require 'dyck'
f = File.open('book.mobi')
mobi = Dyck::Mobi::read(f)
# Access Mobi data
mobi.title
mobi.publishing_date
mobi.author
mobi.mobi6.parts # Document text in MOBI6 format
mobi.kf8.parts # Document text in KF8 format
mobi.resources # Images, fonts, audio, video
Writing new Mobi file:
require 'dyck'
mobi = Dyck::Mobi.new
# Fill file metadata
mobi.title = 'Moby Dick'
mobi.publishing_date = Time.parse('October 18, 1851')
mobi.author = 'Herman Melville'
mobi.subjects = %w[whale sea]
mobi.description = "The book is the sailor Ishmael's narrative of the obsessive quest of Ahab," \
" captain of the whaling ship Pequod, for revenge on Moby Dick, the giant white sperm whale " \
"that on the ship's previous voyage bit off Ahab's leg at the knee."
# Add MOBI6 data
mobi.mobi6 = Dyck::MobiData.new
mobi.mobi6.parts << '<html><body>Book text in MOBI6 format</body></html>'
# And/or, add KF8 data
mobi.kf8 = Dyck::MobiData.new
mobi.kf8.parts << '<html><body>Book text in KF8 format</body></html>'
# Write to file
File.open('moby-dick.mobi', 'wb') do |f|
mobi.write(f)
end