class KindleManager::FileStore

Constants

TIME_FORMAT_FOR_FILENAME

Attributes

dir_name[RW]
session[RW]
sub_dir[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/kindle_manager/file_store.rb, line 7
def initialize(options = {})
  @sub_dir = options.fetch(:sub_dir, 'books').to_s
  @dir_name = options.fetch(:dir_name) do
    tmp_dir_name = options[:create] ? nil : find_latest_dir_name
    tmp_dir_name.presence || Time.current.strftime("%Y%m%d%H%M%S")
  end
  @session = options.fetch(:session, nil)
end

Public Instance Methods

find_latest_dir_name() click to toggle source
# File lib/kindle_manager/file_store.rb, line 24
def find_latest_dir_name
  list_work_dirs.sort.last.to_s.split('/').last
end
html_path(time) click to toggle source
# File lib/kindle_manager/file_store.rb, line 32
def html_path(time)
  build_filepath(time, 'html')
end
image_path(time) click to toggle source
# File lib/kindle_manager/file_store.rb, line 36
def image_path(time)
  build_filepath(time, 'png')
end
list_html_files() click to toggle source
# File lib/kindle_manager/file_store.rb, line 28
def list_html_files
  Dir[File.join(Capybara.save_path, target_dir,'*.html')].select{|f| File.file? f }
end
list_work_dirs() click to toggle source
# File lib/kindle_manager/file_store.rb, line 20
def list_work_dirs
  Dir[File.join(Capybara.save_path, sub_dir,'*')].select{|f| File.directory? f }
end
record_page() click to toggle source
# File lib/kindle_manager/file_store.rb, line 40
def record_page
  time = Time.current
  @session.save_page(html_path(time))
  @session.save_screenshot(image_path(time))
end
target_dir() click to toggle source
# File lib/kindle_manager/file_store.rb, line 16
def target_dir
  File.join(sub_dir, dir_name)
end

Private Instance Methods

build_filepath(time, ext) click to toggle source
# File lib/kindle_manager/file_store.rb, line 48
def build_filepath(time, ext)
  File.join(target_dir, "#{time.strftime(TIME_FORMAT_FOR_FILENAME)}#{(time.usec / 1000.0).round.to_s.rjust(3,'0')}.#{ext}")
end