Class: Verkilo::Shelf

Inherits:
Object
  • Object
show all
Defined in:
lib/verkilo/shelf.rb

Instance Method Summary collapse

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

#booksObject



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_iObject 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_sObject Also known as: title



10
11
12
# File 'lib/verkilo/shelf.rb', line 10

def to_s
  File.basename(@root_dir)
end