Class: WordTree::Library
- Inherits:
-
Object
- Object
- WordTree::Library
- Defined in:
- lib/wordtree/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
#initialize(root) ⇒ Library
Returns a new instance of Library.
16 17 18 |
# File 'lib/wordtree/library.rb', line 16 def initialize(root) @root = root end |
Instance Attribute Details
#root ⇒ Object (readonly)
The file path to the root of the library directory, e.g. /data/library
14 15 16 |
# File 'lib/wordtree/library.rb', line 14 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
22 23 24 |
# File 'lib/wordtree/library.rb', line 22 def dir_of(book_id) File.(LibraryLocator.identity(book_id).relpath, root) end |
#file_type(book_id, type = :raw) ⇒ Object
30 31 32 33 |
# File 'lib/wordtree/library.rb', line 30 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
37 38 39 |
# File 'lib/wordtree/library.rb', line 37 def mkdir(book_id) FileUtils.mkdir_p(dir_of(book_id)) end |
#path_to(book_id, type = :raw) ⇒ Object
26 27 28 |
# File 'lib/wordtree/library.rb', line 26 def path_to(book_id, type=:raw) File.join(dir_of(book_id), file_type(book_id, type)) end |