Class: WordTree::Disk::LibraryLocator
- Inherits:
-
Object
- Object
- WordTree::Disk::LibraryLocator
- Defined in:
- lib/wordtree/disk/library_locator.rb
Overview
A class that converts from a book ID to a location within the library, e.g.
“firstbooknapole00gruagoog”
becomes
“fi/og/firstbooknapole00gruagoog/”
or, in context of the full path:
- /data/library/
-
“fi/og/firstbooknapole00gruagoog/” [firstbooknapole00gruagoog.md]
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
The book ID to locate.
Class Method Summary collapse
-
.identity(id) ⇒ Object
Constructor that is as willing to use a String as it is a LibraryLocator.
Instance Method Summary collapse
- #first ⇒ Object
-
#initialize(id) ⇒ LibraryLocator
constructor
Construct a LibraryLocator from a string (book ID).
- #last ⇒ Object
-
#relpath ⇒ Object
Returns a “relative” path to be joined to the library root, e.g.
Constructor Details
#initialize(id) ⇒ LibraryLocator
Construct a LibraryLocator from a string (book ID)
20 21 22 |
# File 'lib/wordtree/disk/library_locator.rb', line 20 def initialize(id) @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
The book ID to locate
17 18 19 |
# File 'lib/wordtree/disk/library_locator.rb', line 17 def id @id end |
Class Method Details
.identity(id) ⇒ Object
Constructor that is as willing to use a String as it is a LibraryLocator
41 42 43 |
# File 'lib/wordtree/disk/library_locator.rb', line 41 def self.identity(id) id.is_a?(LibraryLocator) ? id : new(id) end |
Instance Method Details
#first ⇒ Object
24 25 26 |
# File 'lib/wordtree/disk/library_locator.rb', line 24 def first @id[0..1].downcase end |
#last ⇒ Object
28 29 30 |
# File 'lib/wordtree/disk/library_locator.rb', line 28 def last @id[-2..-1].downcase end |
#relpath ⇒ Object
Returns a “relative” path to be joined to the library root, e.g. if the identifier is “firstbooknapole00gruagoog”, then relpath should return “fi/og/firstbooknapole00gruagoog”, i.e. probably later to become something like “/data/library/fi/og/firstbooknapole00gruagoog”
36 37 38 |
# File 'lib/wordtree/disk/library_locator.rb', line 36 def relpath File.join(first, last, @id) end |