Sha256: 70ea1707fbf8d2b730174a8f9cc2944b9e818adb2800c351e9c576882149efd4

Contents?: true

Size: 738 Bytes

Versions: 8

Compression:

Stored size: 738 Bytes

Contents

module Bookmaker
  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

8 entries across 8 versions & 1 rubygems

Version Path
bookmaker-0.6.0 lib/bookmaker/stats.rb
bookmaker-0.5.5 lib/bookmaker/stats.rb
bookmaker-0.5.2 lib/bookmaker/stats.rb
bookmaker-0.5.0 lib/bookmaker/stats.rb
bookmaker-0.4.0 lib/bookmaker/stats.rb
bookmaker-0.3.1 lib/bookmaker/stats.rb
bookmaker-0.2.0 lib/bookmaker/stats.rb
bookmaker-0.1.0 lib/bookmaker/stats.rb