Sha256: 7d71ac112c64e001bbbf9e3c64600eaf57d261fdfb3a539bf9cc52f3f0c07fdd

Contents?: true

Size: 803 Bytes

Versions: 13

Compression:

Stored size: 803 Bytes

Contents

require "kindlegen"
require "tempfile"

module NcodeSyosetu
  module Builder
    class Mobi
      def self.write(novel, mobi_path)
        mobi_pathname = Pathname.new(mobi_path)
        mobi_basename = mobi_pathname.basename.to_s
        Dir.mktmpdir do |tmpdir|
          epub_path = File.join(tmpdir, "#{mobi_basename}.epub")
          NcodeSyosetu::Builder::Epub3.write(novel, epub_path)
          STDERR.puts Kindlegen.run(epub_path,
                        "-verbose",
                        "-locale", "ja",
                        "-o", mobi_basename)
          File.rename(File.join(tmpdir, mobi_basename), mobi_path)
        end
      end
    end
  end

  NcodeSyosetu::Model::Novel.class_eval do
    def write_mobi(file)
      NcodeSyosetu::Builder::Mobi.write(self, file)
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
ncode-syosetu-mobi-0.2.3 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-mobi-0.2.2 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-mobi-0.2.1 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-mobi-0.2.0 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-mobi-0.1.2 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-mobi-0.1.1 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-mobi-0.1.0 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-0.0.7 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-0.0.6 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-0.0.5 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-0.0.4 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-0.0.3 lib/ncode_syosetu/builder/mobi.rb
ncode-syosetu-0.0.2 lib/ncode_syosetu/builder/mobi.rb