Class: Bookbinder::Operations
- Inherits:
-
Object
- Object
- Bookbinder::Operations
- Defined in:
- lib/bookbinder/operations.rb
Class Method Summary collapse
-
.convert(src_path, dest_path) ⇒ Object
This will take the ebook at src_path, map it, then convert it to the format recognized in dest_path.
- .map(path) ⇒ Object
-
.normalize(path) ⇒ Object
This will REPLACE the ebook with itself, after POSSIBLY LOSSY parsing by Bookbinder.
- .package_classes ⇒ Object
-
.recognize(path) ⇒ Object
This inspects a path and gives you the package class that probably can read or write it.
- .validate(path) ⇒ Object
Class Method Details
.convert(src_path, dest_path) ⇒ Object
This will take the ebook at src_path, map it, then convert it to the format recognized in dest_path. Be aware that ANYTHING already at dest_path will be replaced.
51 52 53 54 55 56 57 58 |
# File 'lib/bookbinder/operations.rb', line 51 def convert(src_path, dest_path) src_klass = recognize(src_path) dest_klass = recognize(dest_path) src_pkg = src_klass.read(src_path) dest_pkg = src_pkg.export(dest_klass) dest_pkg.write(dest_path) [src_pkg, dest_pkg] end |
.map(path) ⇒ Object
22 23 24 |
# File 'lib/bookbinder/operations.rb', line 22 def map(path) JSON.pretty_generate(validate(path).map) end |
.normalize(path) ⇒ Object
This will REPLACE the ebook with itself, after POSSIBLY LOSSY parsing by Bookbinder. Be careful! If you want to copy-and-normalize, use convert.
39 40 41 42 43 44 |
# File 'lib/bookbinder/operations.rb', line 39 def normalize(path) pkg_klass = recognize(path) pkg = pkg_klass.read(path) pkg.write(path) pkg end |
.package_classes ⇒ Object
5 6 7 8 9 |
# File 'lib/bookbinder/operations.rb', line 5 def package_classes ObjectSpace.each_object(Class).select { |klass| klass < Bookbinder::Package } end |
.recognize(path) ⇒ Object
This inspects a path and gives you the package class that probably can read or write it.
15 16 17 18 19 |
# File 'lib/bookbinder/operations.rb', line 15 def recognize(path) package_classes.detect { |klass| klass.recognize(path) } || raise(Bookbinder::UnknownFormat, path) end |
.validate(path) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/bookbinder/operations.rb', line 27 def validate(path) pkg_klass = recognize(path) pkg = pkg_klass.read(path) # TODO: emit warnings? pkg end |