Class: Bookshelf::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/bookshelf/stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_dir) ⇒ Stats

Returns a new instance of Stats.



5
6
7
# File 'lib/bookshelf/stats.rb', line 5

def initialize(root_dir)
  @root_dir = root_dir
end

Instance Attribute Details

#root_dirObject (readonly)

Returns the value of attribute root_dir.



3
4
5
# File 'lib/bookshelf/stats.rb', line 3

def root_dir
  @root_dir
end

Instance Method Details

#chaptersObject



21
22
23
# File 'lib/bookshelf/stats.rb', line 21

def chapters
  @chapters ||= html.css(".chapter").size
end

#contentObject



33
34
35
# File 'lib/bookshelf/stats.rb', line 33

def content
  @content ||= Parser::HTML.new(root_dir).content
end

#htmlObject



13
14
15
# File 'lib/bookshelf/stats.rb', line 13

def html
  @html ||= Nokogiri::HTML(content)
end

#imagesObject



25
26
27
# File 'lib/bookshelf/stats.rb', line 25

def images
  @images ||= html.css("img").size
end


29
30
31
# File 'lib/bookshelf/stats.rb', line 29

def links
  @links ||= html.css("[href^='http']").size
end

#textObject



9
10
11
# File 'lib/bookshelf/stats.rb', line 9

def text
  @text ||= html.text
end

#wordsObject



17
18
19
# File 'lib/bookshelf/stats.rb', line 17

def words
  @words ||= text.split(" ").size
end