Class: Guard::Gimli::Converter

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Converter

Returns a new instance of Converter.



5
6
7
# File 'lib/guard/gimli/converter.rb', line 5

def initialize(options)
  @outputdir = options[:outputdir]
end

Instance Method Details

#base_dir(path) ⇒ Object



45
46
47
48
# File 'lib/guard/gimli/converter.rb', line 45

def base_dir(path)
  dir = File.dirname path
  dir unless dir == '.'
end

#command(path) ⇒ Object



18
19
20
21
# File 'lib/guard/gimli/converter.rb', line 18

def command(path)
  command = " -f #{escape(path)}"
  command += outputdir(escape(path)).nil? ? '' : " -o #{outputdir(escape(path))}"
end

#escape(path) ⇒ Object



50
51
52
# File 'lib/guard/gimli/converter.rb', line 50

def escape(path)
  path.gsub(' ', '\ ')
end

#filename(path) ⇒ Object



41
42
43
# File 'lib/guard/gimli/converter.rb', line 41

def filename(path)
  File.basename(path).gsub(/\..+$/, '')
end

#outputdir(path) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/guard/gimli/converter.rb', line 23

def outputdir(path)
  if @outputdir.nil?
    base_dir path
  else
    if base_dir(path).nil?
      @outputdir
    else
      File.join(base_dir(path), @outputdir)
    end
  end
end

#outputinfo(path) ⇒ Object



35
36
37
38
39
# File 'lib/guard/gimli/converter.rb', line 35

def outputinfo(path)
  info = outputdir(path)
  info += '/' unless info.nil?
  info = info.to_s + "#{filename(path)}.pdf"
end

#reload(paths = []) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/guard/gimli/converter.rb', line 9

def reload(paths = [])
  UI.info "Building pdfs for #{paths.join(' ')}"
  start_at = Time.now
  paths.each do |path|
    system("gimli#{command(path)}")
    UI.info "#{outputinfo(path)} built"
  end
end