Class: Verkilo::Shelf
- Inherits:
-
Object
- Object
- Verkilo::Shelf
- Defined in:
- lib/verkilo/shelf.rb
Instance Method Summary collapse
- #books ⇒ Object
-
#initialize(root_dir) ⇒ Shelf
constructor
A new instance of Shelf.
- #to_i ⇒ Object (also: #wordcount)
- #to_s ⇒ Object (also: #title)
Constructor Details
#initialize(root_dir) ⇒ Shelf
Returns a new instance of Shelf.
3 4 5 6 7 8 9 |
# File 'lib/verkilo/shelf.rb', line 3 def initialize(root_dir) cmd = "basename -s .git `git config --get remote.origin.url`" @repo = `#{cmd}`.strip || root_dir @root_dir = root_dir @books = [] @wordcount = Hash.new end |
Instance Method Details
#books ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/verkilo/shelf.rb', line 23 def books return @books unless @books.empty? @books = Dir["#{@root_dir}/**/.book"].map do |book_flag| dir = File.dirname(book_flag) title = File.basename(dir) Book.new(title, dir, @repo) end end |
#to_i ⇒ Object Also known as: wordcount
15 16 17 18 19 20 |
# File 'lib/verkilo/shelf.rb', line 15 def to_i self.books.each do |b| @wordcount[b.title] = b.to_i end return @wordcount end |
#to_s ⇒ Object Also known as: title
10 11 12 |
# File 'lib/verkilo/shelf.rb', line 10 def to_s File.basename(@root_dir) end |