class Microstation::Dir

Attributes

dir[R]
relative_pdf_path[R]

Public Class Methods

Dir(path) click to toggle source
# File lib/microstation/dir.rb, line 17
def self.Dir(path)
  case path
  when Microstation::Dir
    path
  else
    new(Pathname(path))
  end
end
new(dir,pdf_path=nil) click to toggle source
# File lib/microstation/dir.rb, line 12
def initialize(dir,pdf_path=nil)
  @dir = Pathname(dir).expand_path
  @relative_pdf_path = set_relative_pdf_path(pdf_path)
end

Public Instance Methods

+(other) click to toggle source
# File lib/microstation/dir.rb, line 55
def +(other)
  self.class.new( self.path + other)
end
==(other) click to toggle source
# File lib/microstation/dir.rb, line 26
def ==(other)
  self.dir == other.dir && self.relative_pdf_path == other.relative_pdf_path
end
concat_pdfs(files) click to toggle source
# File lib/microstation/dir.rb, line 108
def concat_pdfs(files)
  Pdftk.concat(files)
end
copy(drawing,dir) click to toggle source
# File lib/microstation/dir.rb, line 60
def copy(drawing,dir)
  cp drawing, dir
end
directory?() click to toggle source
# File lib/microstation/dir.rb, line 38
def directory?
  path.directory?
end
drawing_files() click to toggle source
# File lib/microstation/dir.rb, line 88
def drawing_files
  return @drawing_files if @drawing_files
  set_drawing_files(drawings.map{|dwg| Microstation::Drawing::File.new(dwg)} )
  @drawing_files
end
drawing_files_needing_pdf(dir = pdf_dirname) click to toggle source
# File lib/microstation/dir.rb, line 112
def drawing_files_needing_pdf(dir = pdf_dirname)
  drawing_files.select{|d| d.needs_pdf?(dir) }
end
drawings() click to toggle source
# File lib/microstation/dir.rb, line 75
def drawings
  Pathname.glob(@dir + "*.d{gn,wg}")
end
exist?() click to toggle source
# File lib/microstation/dir.rb, line 42
def exist?
  path.exist?
end
find_by_name(re) click to toggle source
# File lib/microstation/dir.rb, line 70
def find_by_name(re)
  re = Regexp.new(re)
  drawing_files.find{|n| n.to_path =~ re}
end
find_pdftk(dirs = nil) click to toggle source
# File lib/microstation/dir.rb, line 127
def find_pdftk(dirs = nil)
  require 'pdf_forms'
  @pdftk = PdfForms.new('e:/tools/pdftk-1.44/bin/pdftk.exe')
end
generate_pdfs(dir = pdf_dirname) click to toggle source
# File lib/microstation/dir.rb, line 122
def generate_pdfs(dir = pdf_dirname)
  print_pdfs(dir)
  concat_pdfs(pdf_files(dir), dir + "dir.combined.drawings.pdf")
end
get_meta_for_drawings() click to toggle source
# File lib/microstation/dir.rb, line 144
def get_meta_for_drawings
  @drawing_files = nil
  files = []
  with_drawing_files( drawings) do |drawing|
    files << Microstation::Drawing::File.from_drawing(drawing)
  end
  set_drawing_files(files)
end
mkdir() click to toggle source
# File lib/microstation/dir.rb, line 47
def mkdir
  @dir.mkdir
end
mkpath() click to toggle source
# File lib/microstation/dir.rb, line 51
def mkpath
  @dir.mkpath
end
path() click to toggle source
# File lib/microstation/dir.rb, line 34
def path
  @dir
end
pdf_dirname() click to toggle source
# File lib/microstation/dir.rb, line 157
def pdf_dirname
  if relative_pdf_path.absolute?
    relative_pdf_path
  else
    dir + relative_pdf_path
  end
end
pdf_files(dir = pdf_dirname) click to toggle source
# File lib/microstation/dir.rb, line 104
def pdf_files(dir = pdf_dirname)
  sort(drawing_files).map{|p| p.pdf_name(dir)}
end
pdf_generation_complete?() click to toggle source
# File lib/microstation/dir.rb, line 99
def pdf_generation_complete?
  drawing_files.all?{|d| not d.needs_pdf?}
end
pdftk() click to toggle source
# File lib/microstation/dir.rb, line 132
def pdftk
  @pdftk ||= find_pdftk(dirs= nil)
end
print_pdfs(dir = pdf_dirname) click to toggle source
relative_pdf_path=(path) click to toggle source
# File lib/microstation/dir.rb, line 171
def relative_pdf_path=(path)
  @relative_pdf_path = set_relative_path(path)
end
select_by_name( re) click to toggle source
# File lib/microstation/dir.rb, line 64
def select_by_name( re)
  re = Regexp.new(re)
  drawing_files.select{|n| n.to_path =~ re}
end
set_drawing_files(dfiles) click to toggle source
# File lib/microstation/dir.rb, line 94
def set_drawing_files(dfiles)
  @drawing_files = sort(dfiles)
end
set_relative_pdf_path(path) click to toggle source
# File lib/microstation/dir.rb, line 165
def set_relative_pdf_path(path)
  rel_path = path.nil? ? "." : path
  Pathname(rel_path)
end
sort(array_of_files) click to toggle source
# File lib/microstation/dir.rb, line 83
def sort(array_of_files)
  sort_lambda = @sort_by || lambda{|f| f.path.to_s}
  array_of_files.sort_by(&sort_lambda)
end
sort_by(&block) click to toggle source
# File lib/microstation/dir.rb, line 79
def sort_by(&block)
  @sort_by = block
end
to_path() click to toggle source
# File lib/microstation/dir.rb, line 30
def to_path
  @dir.to_path
end
with_drawing_files(dwgs = drawing_files, &block) click to toggle source
# File lib/microstation/dir.rb, line 153
def with_drawing_files(dwgs = drawing_files, &block)
  Microstation.with_drawings(dwgs,&block)
end