Class: WordTree::Disk::Library
- Inherits:
-
Object
- Object
- WordTree::Disk::Library
- Defined in:
- lib/wordtree/disk/library.rb
Constant Summary collapse
- FILE_TYPES =
{ :raw => "%s.md" }
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
The file path to the root of the library directory, e.g.
Instance Method Summary collapse
-
#dir_of(book_id) ⇒ Object
returns the full path of a book’s subdirectory within the library Accepts either a String or a LibraryLocator object.
- #file_type(book_id, type = :raw) ⇒ Object
-
#initialize(root) ⇒ Library
constructor
A new instance of Library.
-
#mkdir(book_id) ⇒ Object
Create all subdirs up to the location where a book is stored Accepts either a String or a LibraryLocator object.
- #path_to(book_id, type = :raw) ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
The file path to the root of the library directory, e.g. /data/library
15 16 17 |
# File 'lib/wordtree/disk/library.rb', line 15 def root @root end |
Instance Method Details
#dir_of(book_id) ⇒ Object
returns the full path of a book’s subdirectory within the library Accepts either a String or a LibraryLocator object
23 24 25 |
# File 'lib/wordtree/disk/library.rb', line 23 def dir_of(book_id) File.(LibraryLocator.identity(book_id).relpath, root) end |
#file_type(book_id, type = :raw) ⇒ Object
31 32 33 34 |
# File 'lib/wordtree/disk/library.rb', line 31 def file_type(book_id, type=:raw) locator = LibraryLocator.identity(book_id) FILE_TYPES[type] % locator.id end |
#mkdir(book_id) ⇒ Object
Create all subdirs up to the location where a book is stored Accepts either a String or a LibraryLocator object
38 39 40 |
# File 'lib/wordtree/disk/library.rb', line 38 def mkdir(book_id) FileUtils.mkdir_p(dir_of(book_id)) end |
#path_to(book_id, type = :raw) ⇒ Object
27 28 29 |
# File 'lib/wordtree/disk/library.rb', line 27 def path_to(book_id, type=:raw) File.join(dir_of(book_id), file_type(book_id, type)) end |