Class: Tankobon::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/tankobon/converter.rb

Direct Known Subclasses

KindleDXConverter

Instance Method Summary collapse

Constructor Details

#initializeConverter

Returns a new instance of Converter.



3
4
5
6
7
8
9
# File 'lib/tankobon/converter.rb', line 3

def initialize
  utils = [:identify, :convert]
  utils.each do |util|
    raise "Fix your ImageMagick installation, #{util} not in your path." if
      %x[which #{util}].strip == ""
  end
end

Instance Method Details

#convert(file) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/tankobon/converter.rb', line 29

def convert(file)
  %x[convert "#{file}" -format #{format} #{rotation(file)} \
    -colorspace #{colorspace} -resize #{size} -background white \
    -gravity center -extent #{size} "#{converted_name(file)}"
  ]
  clean(file)
end

#rotation(file) ⇒ Object



25
26
27
# File 'lib/tankobon/converter.rb', line 25

def rotation(file)
  will_rotate?(file) ? "-rotate 90" : ""
end

#sizeObject



15
16
17
# File 'lib/tankobon/converter.rb', line 15

def size
  "#{width}x#{height}"
end

#to_procObject



11
12
13
# File 'lib/tankobon/converter.rb', line 11

def to_proc
  method(:convert).to_proc
end

#will_rotate?(file) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/tankobon/converter.rb', line 19

def will_rotate?(file)
  w, h = %x[identify -format "%wx%h" "#{file}"]
    .split('x').map{|x| x.to_i}
  w > h
end