Class: KindleManager::FileStore
- Inherits:
-
Object
- Object
- KindleManager::FileStore
- Defined in:
- lib/kindle_manager/file_store.rb
Constant Summary collapse
- TIME_FORMAT_FOR_FILENAME =
'%Y%m%d%H%M%S'
Instance Attribute Summary collapse
-
#dir_name ⇒ Object
Returns the value of attribute dir_name.
-
#session ⇒ Object
Returns the value of attribute session.
-
#sub_dir ⇒ Object
Returns the value of attribute sub_dir.
Instance Method Summary collapse
- #find_latest_dir_name ⇒ Object
- #html_path(time) ⇒ Object
- #image_path(time) ⇒ Object
-
#initialize(options = {}) ⇒ FileStore
constructor
A new instance of FileStore.
- #list_html_files ⇒ Object
- #list_work_dirs ⇒ Object
- #record_page ⇒ Object
- #target_dir ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ FileStore
Returns a new instance of FileStore.
7 8 9 10 11 12 13 14 |
# File 'lib/kindle_manager/file_store.rb', line 7 def initialize( = {}) @sub_dir = .fetch(:sub_dir, 'books').to_s @dir_name = .fetch(:dir_name) do tmp_dir_name = [:create] ? nil : find_latest_dir_name tmp_dir_name.presence || Time.current.strftime("%Y%m%d%H%M%S") end @session = .fetch(:session, nil) end |
Instance Attribute Details
#dir_name ⇒ Object
Returns the value of attribute dir_name.
5 6 7 |
# File 'lib/kindle_manager/file_store.rb', line 5 def dir_name @dir_name end |
#session ⇒ Object
Returns the value of attribute session.
5 6 7 |
# File 'lib/kindle_manager/file_store.rb', line 5 def session @session end |
#sub_dir ⇒ Object
Returns the value of attribute sub_dir.
5 6 7 |
# File 'lib/kindle_manager/file_store.rb', line 5 def sub_dir @sub_dir end |
Instance Method Details
#find_latest_dir_name ⇒ Object
24 25 26 |
# 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) ⇒ Object
32 33 34 |
# File 'lib/kindle_manager/file_store.rb', line 32 def html_path(time) build_filepath(time, 'html') end |
#image_path(time) ⇒ Object
36 37 38 |
# File 'lib/kindle_manager/file_store.rb', line 36 def image_path(time) build_filepath(time, 'png') end |
#list_html_files ⇒ Object
28 29 30 |
# 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 ⇒ Object
20 21 22 |
# 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 ⇒ Object
40 41 42 43 44 |
# 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 ⇒ Object
16 17 18 |
# File 'lib/kindle_manager/file_store.rb', line 16 def target_dir File.join(sub_dir, dir_name) end |