class PdfScrap::Command::Pdftotext

Constants

COMMAND
PWD
TMP_DIR

Public Instance Methods

build() click to toggle source
Calls superclass method PdfScrap::Command::RawCommand#build
# File lib/pdf_scrap/command/pdftotext.rb, line 9
def build
  command = [super]
  command << "\"#{self.pdf}\""
  command << "\"#{self.export_path}\""
  command.join(" ")
end
execute(*args) { |self| ... } click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 16
def execute(*args, &block)
  if block_given?
    yield(self)
    nil
  else
    self.text
  end
end
execute!(*args, &block) click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 25
def execute!(*args, &block)
  self.make_tmp_dir
  
  `#{self.build}`
  
  result = File.open(export_path, "r") do |f|
    f.read
  end.sub(/\f$/, "")
  
  FileUtils.rm_f(export_path)
  result
end
height=(value) click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 66
def height=(value)
  self[:H] = value
end
region=(value) click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 42
def region=(value)
  value = [value].flatten
  self[:x] = value.shift
  self[:y] = value.shift
  self[:W] = value.shift
  self[:H] = value.shift
end
text(*args) click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 38
def text(*args)
  self.execute!(*args)
end
width=(value) click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 70
def width=(value)
  self[:W] = value
end
x1=(value) click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 50
def x1=(value)
  self[:x] = value
end
x2=(value) click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 58
def x2=(value)
  self[:W] = value - (self[:x]||0)
end
y1=(value) click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 54
def y1=(value)
  self[:y] = value
end
y2=(value) click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 62
def y2=(value)
  self[:H] = value - (self[:y]||0)
end

Protected Instance Methods

export_path() click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 81
def export_path
  File.join(tmp_dir, "#{self.object_id.to_i}")
end
make_tmp_dir() click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 77
def make_tmp_dir
  FileUtils.mkdir_p(tmp_dir)
end

Private Instance Methods

pwd() click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 88
def pwd
  PWD
end
tmp_dir() click to toggle source
# File lib/pdf_scrap/command/pdftotext.rb, line 92
def tmp_dir
  File.join(pwd, TMP_DIR)
end