Class: Docbook::Services::DocumentStats

Inherits:
Object
  • Object
show all
Defined in:
lib/docbook/services/document_stats.rb

Overview

Collects statistics and metadata from a parsed DocBook document.

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ DocumentStats

Returns a new instance of DocumentStats.

Parameters:



8
9
10
# File 'lib/docbook/services/document_stats.rb', line 8

def initialize(document)
  @document = document
end

Instance Method Details

#generateHash

Returns statistics including title, author, section/image/table/code counts.

Returns:

  • (Hash)

    statistics including title, author, section/image/table/code counts



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/docbook/services/document_stats.rb', line 13

def generate
  counts = {
    "sections" => 0,
    "images" => 0,
    "code_blocks" => 0,
    "tables" => 0,
    "index_terms" => 0,
    "bibliography_entries" => 0,
    "xincludes" => 0,
  }

  walk(@document, counts)

  {
    "title" => extract_title,
    "subtitle" => extract_subtitle,
    "author" => extract_author,
    "pubdate" => extract_pubdate,
    "releaseinfo" => extract_releaseinfo,
    "copyright" => extract_copyright,
    "root_element" => root_element_name,
    **counts,
  }
end