Class: Alexandria::ExportLibrary
- Inherits:
-
Object
- Object
- Alexandria::ExportLibrary
- Defined in:
- lib/alexandria/export_library.rb
Instance Method Summary collapse
- #copy_covers(dest) ⇒ Object
- #cover(book) ⇒ Object
- #each(&block) ⇒ Object
- #export_as_bibtex(filename) ⇒ Object
- #export_as_csv_list(filename) ⇒ Object
- #export_as_html(filename, theme) ⇒ Object
- #export_as_ipod_notes(filename, _theme) ⇒ Object
- #export_as_isbn_list(filename) ⇒ Object
- #export_as_onix_xml_archive(filename) ⇒ Object
- #export_as_tellico_xml_archive(filename) ⇒ Object
- #final_cover(book) ⇒ Object
-
#initialize(library, sort_order) ⇒ ExportLibrary
constructor
A new instance of ExportLibrary.
- #name ⇒ Object
Constructor Details
#initialize(library, sort_order) ⇒ ExportLibrary
Returns a new instance of ExportLibrary.
13 14 15 16 |
# File 'lib/alexandria/export_library.rb', line 13 def initialize(library, sort_order) @library = library @sorted = sort_order.sort(library) end |
Instance Method Details
#copy_covers(dest) ⇒ Object
26 27 28 |
# File 'lib/alexandria/export_library.rb', line 26 def copy_covers(dest) @library.copy_covers(dest) end |
#cover(book) ⇒ Object
18 19 20 |
# File 'lib/alexandria/export_library.rb', line 18 def cover(book) @library.cover(book) end |
#each(&block) ⇒ Object
34 35 36 |
# File 'lib/alexandria/export_library.rb', line 34 def each(&block) @sorted.each(&block) end |
#export_as_bibtex(filename) ⇒ Object
87 88 89 90 91 |
# File 'lib/alexandria/export_library.rb', line 87 def export_as_bibtex(filename) File.open(filename, "w") do |io| io << to_bibtex end end |
#export_as_csv_list(filename) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/alexandria/export_library.rb', line 126 def export_as_csv_list(filename) CSV.open(filename, "w", col_sep: ";") do |csv| csv << ["Title", "Authors", "Publisher", "Edition", "ISBN", "Year Published", "Rating(#{Book::DEFAULT_RATING} to #{Book::MAX_RATING_STARS})", "Notes", "Want?", "Read?", "Own?", "Tags"] each do |book| csv << [book.title, book..join(", "), book.publisher, book.edition, book.isbn, book.publishing_year, book., book.notes, (book.want ? "1" : "0"), (book.redd ? "1" : "0"), (book.own ? "1" : "0"), (book. ? book..join(", ") : "")] end end end |
#export_as_html(filename, theme) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/alexandria/export_library.rb', line 75 def export_as_html(filename, theme) FileUtils.mkdir(filename) unless File.exist?(filename) Dir.chdir(filename) do copy_covers("pixmaps") FileUtils.cp_r(theme.pixmaps_directory, "pixmaps") if theme.has_pixmaps? FileUtils.cp(theme.css_file, ".") File.open("index.html", "w") do |io| io << to_xhtml(File.basename(theme.css_file)) end end end |
#export_as_ipod_notes(filename, _theme) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/alexandria/export_library.rb', line 93 def export_as_ipod_notes(filename, _theme) FileUtils.mkdir(filename) unless File.exist?(filename) tempdir = Dir.getwd Dir.chdir(filename) copy_covers("pixmaps") File.open("index.linx", "w") do |io| io.puts "<TITLE>" + name + "</TITLE>" each do |book| io.puts '<A HREF="' + book.ident + '">' + book.title + "</A>" end io.close end each do |book| File.open(book.ident, "w") do |io| io.puts "<TITLE>#{book.title} </TITLE>" # put a link to the book's cover. only works on iPod 5G and above(?). if File.exist?(cover(book)) io.puts '<A HREF="pixmaps/' + book.ident + ".jpg" + '">' + book.title + "</A>" else io.puts book.title end io.puts book..join(", ") io.puts book.edition io.puts((book.isbn || "")) # we need to close the files so the iPod can be ejected/unmounted # without us closing Alexandria io.close end end # Again, allow the iPod to unmount Dir.chdir(tempdir) end |
#export_as_isbn_list(filename) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/alexandria/export_library.rb', line 67 def export_as_isbn_list(filename) File.open(filename, "w") do |io| each do |book| io.puts((book.isbn || "")) end end end |
#export_as_onix_xml_archive(filename) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/alexandria/export_library.rb', line 38 def export_as_onix_xml_archive(filename) dir = Dir.mktmpdir File.open(File.join(dir, "onix.xml"), "w") do |io| to_onix_document.write(io, 0) end copy_covers(File.join(dir, "images")) Dir.chdir(dir) do output = `tar -cjf \"#{filename}\" onix.xml images 2>&1` raise output unless $CHILD_STATUS.success? end FileUtils.rm_rf(File.join(dir, "images")) FileUtils.rm(File.join(dir, "onix.xml")) ensure FileUtils.remove_entry dir end |
#export_as_tellico_xml_archive(filename) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/alexandria/export_library.rb', line 54 def export_as_tellico_xml_archive(filename) File.open(File.join(Dir.tmpdir, "tellico.xml"), "w") do |io| to_tellico_document.write(io, 0) end copy_covers(File.join(Dir.tmpdir, "images")) Dir.chdir(Dir.tmpdir) do output = `zip -q -r \"#{filename}\" tellico.xml images 2>&1` raise output unless $CHILD_STATUS.success? end FileUtils.rm_rf(File.join(Dir.tmpdir, "images")) FileUtils.rm(File.join(Dir.tmpdir, "tellico.xml")) end |
#final_cover(book) ⇒ Object
22 23 24 |
# File 'lib/alexandria/export_library.rb', line 22 def final_cover(book) @library.final_cover(book) end |
#name ⇒ Object
30 31 32 |
# File 'lib/alexandria/export_library.rb', line 30 def name @library.name end |