Sha256: e7e22a53e4f6f452527b477567f453939c6f2ed1e70cb6d294deb9a739caabc5

Contents?: true

Size: 735 Bytes

Versions: 7

Compression:

Stored size: 735 Bytes

Contents

module Kitabu
  class Stats
    attr_reader :root_dir

    def initialize(root_dir)
      @root_dir = root_dir
    end

    def text
      @text ||= html.text
    end

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

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

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

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

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

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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kitabu-2.0.0 lib/kitabu/stats.rb
kitabu-1.0.6 lib/kitabu/stats.rb
kitabu-1.0.5 lib/kitabu/stats.rb
kitabu-1.0.4 lib/kitabu/stats.rb
kitabu-1.0.3 lib/kitabu/stats.rb
kitabu-1.0.2 lib/kitabu/stats.rb
kitabu-1.0.1 lib/kitabu/stats.rb