Class: Bookshelf::Stats
- Inherits:
-
Object
- Object
- Bookshelf::Stats
- Defined in:
- lib/bookshelf/stats.rb
Instance Attribute Summary collapse
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
Instance Method Summary collapse
- #chapters ⇒ Object
- #content ⇒ 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.
5 6 7 |
# File 'lib/bookshelf/stats.rb', line 5 def initialize(root_dir) @root_dir = root_dir end |
Instance Attribute Details
#root_dir ⇒ Object (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
#chapters ⇒ Object
21 22 23 |
# File 'lib/bookshelf/stats.rb', line 21 def chapters @chapters ||= html.css(".chapter").size end |
#content ⇒ Object
33 34 35 |
# File 'lib/bookshelf/stats.rb', line 33 def content @content ||= Parser::HTML.new(root_dir).content end |
#html ⇒ Object
13 14 15 |
# File 'lib/bookshelf/stats.rb', line 13 def html @html ||= Nokogiri::HTML(content) end |
#images ⇒ Object
25 26 27 |
# File 'lib/bookshelf/stats.rb', line 25 def images @images ||= html.css("img").size end |
#links ⇒ Object
29 30 31 |
# File 'lib/bookshelf/stats.rb', line 29 def links @links ||= html.css("[href^='http']").size end |
#text ⇒ Object
9 10 11 |
# File 'lib/bookshelf/stats.rb', line 9 def text @text ||= html.text end |
#words ⇒ Object
17 18 19 |
# File 'lib/bookshelf/stats.rb', line 17 def words @words ||= text.split(" ").size end |