Class: PdfMatcher::PdfFile::Tempfile

Inherits:
Base
  • Object
show all
Defined in:
lib/pdf_matcher/pdf_file.rb

Instance Attribute Summary

Attributes inherited from Base

#data

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Tempfile

Returns a new instance of Tempfile.



48
49
50
51
# File 'lib/pdf_matcher/pdf_file.rb', line 48

def initialize(data)
  super(data: data, path: nil)
  @io = nil
end

Instance Method Details

#closeObject



66
67
68
69
# File 'lib/pdf_matcher/pdf_file.rb', line 66

def close
  @io&.close!
  @io = nil
end

#openObject



53
54
55
56
57
58
59
# File 'lib/pdf_matcher/pdf_file.rb', line 53

def open
  @io ||= ::Tempfile.open do |f|
    f.binmode
    f.puts data
    f
  end
end

#pathObject



61
62
63
64
# File 'lib/pdf_matcher/pdf_file.rb', line 61

def path
  path = @io&.path
  path ? Pathname(path) : nil
end