Class: ComicBook::CLIHelpers
- Inherits:
-
Object
- Object
- ComicBook::CLIHelpers
- Defined in:
- lib/comic_book/cli_helpers.rb
Class Method Summary collapse
- .binary_path(name) ⇒ Object
- .check_linux_dependency!(name) ⇒ Object
- .lsar_list(archive_path) ⇒ Object
- .unar_extract(archive_path, destination) ⇒ Object
Class Method Details
.binary_path(name) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/comic_book/cli_helpers.rb', line 7 def binary_path name case RUBY_PLATFORM when /darwin/ File. "../vendor/macos/#{name}", __FILE__ when /linux/ check_linux_dependency! name name when /mingw/ File. "../vendor/windows/#{name}", __FILE__ else raise "Unsupported platform: #{RUBY_PLATFORM}" end end |
.check_linux_dependency!(name) ⇒ Object
21 22 23 24 25 |
# File 'lib/comic_book/cli_helpers.rb', line 21 def check_linux_dependency! name return if system("which #{name} > /dev/null 2>&1") raise Error, "#{name} is not installed. Install with: sudo apt-get install unar (Ubuntu/Debian)" end |
.lsar_list(archive_path) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/comic_book/cli_helpers.rb', line 27 def lsar_list archive_path bin_path = binary_path 'lsar' output, status = Open3.capture2e(bin_path, archive_path) raise Error, "lsar failed: #{output}" unless status.success? output.lines.drop(1).map(&:chomp).reject(&:empty?) end |
.unar_extract(archive_path, destination) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/comic_book/cli_helpers.rb', line 37 def unar_extract archive_path, destination bin_path = binary_path 'unar' output, status = Open3.capture2e( bin_path, '-o', destination, '-f', '-D', archive_path ) raise Error, "unar extraction failed: #{output}" unless status.success? output end |