Class: WordTree::LibraryLocator
- Inherits:
-
Object
- Object
- WordTree::LibraryLocator
- Defined in:
- lib/wordtree/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)
19 20 21 |
# File 'lib/wordtree/library_locator.rb', line 19 def initialize(id) @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
The book ID to locate
16 17 18 |
# File 'lib/wordtree/library_locator.rb', line 16 def id @id end |
Class Method Details
.identity(id) ⇒ Object
Constructor that is as willing to use a String as it is a LibraryLocator
40 41 42 |
# File 'lib/wordtree/library_locator.rb', line 40 def self.identity(id) id.is_a?(LibraryLocator) ? id : new(id) end |
Instance Method Details
#first ⇒ Object
23 24 25 |
# File 'lib/wordtree/library_locator.rb', line 23 def first @id[0..1].downcase end |
#last ⇒ Object
27 28 29 |
# File 'lib/wordtree/library_locator.rb', line 27 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”
35 36 37 |
# File 'lib/wordtree/library_locator.rb', line 35 def relpath File.join(first, last, @id) end |