Class: Kitabu::Stats

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_dir) ⇒ Stats

Returns a new instance of Stats.



7
8
9
# File 'lib/kitabu/stats.rb', line 7

def initialize(root_dir)
  @root_dir = root_dir
end

Instance Attribute Details

#root_dirObject (readonly)

Returns the value of attribute root_dir.



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

def root_dir
  @root_dir
end

Instance Method Details

#chaptersObject



23
24
25
# File 'lib/kitabu/stats.rb', line 23

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

#code_blocksObject



39
40
41
# File 'lib/kitabu/stats.rb', line 39

def code_blocks
  @code_blocks ||= html.css("pre").size
end

#contentObject



43
44
45
# File 'lib/kitabu/stats.rb', line 43

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

#footnotesObject



31
32
33
# File 'lib/kitabu/stats.rb', line 31

def footnotes
  @footnotes ||= html.css("p.footnote").size
end

#htmlObject



15
16
17
# File 'lib/kitabu/stats.rb', line 15

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

#imagesObject



27
28
29
# File 'lib/kitabu/stats.rb', line 27

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


35
36
37
# File 'lib/kitabu/stats.rb', line 35

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

#textObject



11
12
13
# File 'lib/kitabu/stats.rb', line 11

def text
  @text ||= html.text
end

#wordsObject



19
20
21
# File 'lib/kitabu/stats.rb', line 19

def words
  @words ||= text.split.size
end