Class: DjVused

Inherits:
Object
  • Object
show all
Defined in:
lib/djvu-tools/djvused.rb

Overview

Interface to djvused.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ DjVused

Returns a new instance of DjVused.

Raises:

  • (SystemCallError)

See Also:

  • #new


8
9
10
11
12
13
14
# File 'lib/djvu-tools/djvused.rb', line 8

def initialize file
  raise SystemCallError, 'djvused command not found' if ( Which::which 'djvused' ).empty?

  @file = File.expand_path file
  raise RuntimeError, 'File not found' unless ( File.exists? @file )
  @command = ""
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



5
6
7
# File 'lib/djvu-tools/djvused.rb', line 5

def command
  @command
end

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/djvu-tools/djvused.rb', line 4

def file
  @file
end

Instance Method Details

#saveObject

Runs djvused with command and saves to file.



28
29
30
# File 'lib/djvu-tools/djvused.rb', line 28

def save
  system *['djvused', '-s','-e', @command, @file]
end

#title_page(page, title) ⇒ String

Appends command to set page title.

Parameters:

  • page (Integer)

    number

  • title (String)

    cannot contain single or double quotes

Returns:

  • (String)

    command string

Raises:

  • (ArgumentError)


20
21
22
23
24
25
# File 'lib/djvu-tools/djvused.rb', line 20

def title_page page, title
  raise ArgumentError, 'Argument is not an integer' unless page.is_a? Integer
  raise ArgumentError, 'Argument is cannot contain a single or double quote' if title =~ /['"]/

  @command << %Q{select #{page}; set-page-title "#{title}";}
end