lib/aipp/pdf.rb in aipp-0.2.2 vs lib/aipp/pdf.rb in aipp-0.2.3
- old
+ new
@@ -95,16 +95,16 @@
pages = ::PDF::Reader.new(@file).pages
[pages.map(&:text).join("\f"), page_ranges_for(pages)]
end
def read_cache
- cache_file = "#{@file}.json"
- if File.exist?(cache_file) && (File.stat(@file).mtime - File.stat(cache_file).mtime).abs < 1
- JSON.load File.read(cache_file)
+ cache_file = Pathname.new("#{@file}.json")
+ if cache_file.exist? && (@file.stat.mtime - cache_file.stat.mtime).abs < 1
+ JSON.load cache_file
else
read.tap do |data|
- File.write(cache_file, data.to_json)
- FileUtils.touch(cache_file, mtime: File.stat(@file).mtime)
+ cache_file.write data.to_json
+ FileUtils.touch(cache_file, mtime: @file.stat.mtime)
end
end
end
def page_ranges_for(pages)