How to measure the size of the current knowledge base

We start by considering all pages from the current database, except the table of contents page because it's not particularly relevant for the size of the content:

pages := thisSnippet database pages reject: [:each | 
	each title = 'Glamorous Toolkit Book'].
  

Measuring words and snippets

Measuring the words:

totalWords := pages
	sumNumbers: [ :aPage | 
		| string |
		string := String cr join: (aPage allChildrenBreadthFirst collect: #contentAsString).
		(string piecesCutWhere: [ :a :b | a isSeparator ]) size ]
  

Measuring the snippets size:

pages sumNumbers: [ :aPage | aPage allChildrenBreadthFirst size ].
  

Measuring the size of embedded examples

Some snippets contain more details than others. For instance, an example snippet embeds the source of the example method. Consider a page like this: Drawing graphs with Mondrian by example.

So, we could count the size of the examples, as well.

allExampleSnippets := pages
		flatCollect: [ :aPage | 
			aPage allChildrenBreadthFirst
				select: [ :each | each isKindOf: LeExampleSnippet ] ].
examplesWords := allExampleSnippets
		sumNumbers: [ :each | 
			each exampleMethod
				ifNil: [ 0 ]
				ifNotNil: [ :m | (m compiledMethod sourceCode piecesCutWhere: [ :a :b | a isSeparator ]) size ] ].
  

Of course, we count the size of the source code of the embedded example, we should not count the definition of the example snippet itself.

examplesDefinitionWords := allExampleSnippets
		sumNumbers: [ :each | (each contentAsString piecesCutWhere: [ :a :b | a isSeparator ]) size ].
examplesTotalWords := examplesWords - examplesDefinitionWords.
  

So, now if we look at the total amount of words, we get:

totalWords + examplesTotalWords