Class: Coradoc::Introspection::ElementCounter
- Inherits:
-
Visitor::Base
- Object
- Visitor::Base
- Coradoc::Introspection::ElementCounter
- Defined in:
- lib/coradoc/introspection/element_counter.rb
Overview
Visitor that walks a document and counts each CoreModel node by its type key. Used by Introspection.count_element_types to back the Coradoc.document_stats API.
Typed StructuralElement / Block nodes are counted under their element_type (semantic identity). Other nodes fall back to a snake_case rendering of their class name.
Instance Attribute Summary collapse
-
#counts ⇒ Object
readonly
Returns the value of attribute counts.
Instance Method Summary collapse
-
#initialize ⇒ ElementCounter
constructor
A new instance of ElementCounter.
- #visit(element) ⇒ Object
Methods inherited from Visitor::Base
#visit_abbreviation, #visit_annotation_block, #visit_array, #visit_bibliography, #visit_bibliography_entry, #visit_block, #visit_definition_item, #visit_definition_list, #visit_element_attribute, #visit_footnote, #visit_footnote_reference, #visit_image, #visit_inline_element, #visit_list_block, #visit_list_item, #visit_metadata, #visit_metadata_entry, #visit_structural_element, #visit_table, #visit_table_cell, #visit_table_row, #visit_term, #visit_toc, #visit_toc_entry, #visit_unknown
Constructor Details
#initialize ⇒ ElementCounter
Returns a new instance of ElementCounter.
13 14 15 |
# File 'lib/coradoc/introspection/element_counter.rb', line 13 def initialize @counts = Hash.new(0) end |
Instance Attribute Details
#counts ⇒ Object (readonly)
Returns the value of attribute counts.
17 18 19 |
# File 'lib/coradoc/introspection/element_counter.rb', line 17 def counts @counts end |