Class: Kitabu::Stats
- Inherits:
-
Object
- Object
- Kitabu::Stats
- Defined in:
- lib/kitabu/stats.rb
Instance Attribute Summary collapse
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
Instance Method Summary collapse
- #chapters ⇒ Object
- #code_blocks ⇒ Object
- #content ⇒ Object
- #footnotes ⇒ Object
- #html ⇒ Object
- #images ⇒ Object
-
#initialize(root_dir) ⇒ Stats
constructor
A new instance of Stats.
- #links ⇒ Object
- #text ⇒ Object
- #words ⇒ Object
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_dir ⇒ Object (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
#chapters ⇒ Object
23 24 25 |
# File 'lib/kitabu/stats.rb', line 23 def chapters @chapters ||= html.css(".chapter").size end |
#code_blocks ⇒ Object
39 40 41 |
# File 'lib/kitabu/stats.rb', line 39 def code_blocks @code_blocks ||= html.css("pre").size end |
#content ⇒ Object
43 44 45 |
# File 'lib/kitabu/stats.rb', line 43 def content @content ||= Exporter::HTML.new(root_dir).content end |
#footnotes ⇒ Object
31 32 33 |
# File 'lib/kitabu/stats.rb', line 31 def footnotes @footnotes ||= html.css("p.footnote").size end |
#html ⇒ Object
15 16 17 |
# File 'lib/kitabu/stats.rb', line 15 def html @html ||= Nokogiri::HTML(content) end |
#images ⇒ Object
27 28 29 |
# File 'lib/kitabu/stats.rb', line 27 def images @images ||= html.css("img").size end |
#links ⇒ Object
35 36 37 |
# File 'lib/kitabu/stats.rb', line 35 def links @links ||= html.css("[href^='http']").size end |
#text ⇒ Object
11 12 13 |
# File 'lib/kitabu/stats.rb', line 11 def text @text ||= html.text end |
#words ⇒ Object
19 20 21 |
# File 'lib/kitabu/stats.rb', line 19 def words @words ||= text.split.size end |