To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 7a / 7acfd8a3d508663aeabae0309fddb7dc899a74cf.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (558 Bytes)
| 1 |
module CodeRay |
|---|---|
| 2 |
module Encoders |
| 3 |
|
| 4 |
# Returns the number of tokens. |
| 5 |
# |
| 6 |
# Text and block tokens are counted. |
| 7 |
class Count < Encoder |
| 8 |
|
| 9 |
register_for :count |
| 10 |
|
| 11 |
protected |
| 12 |
|
| 13 |
def setup options |
| 14 |
super |
| 15 |
|
| 16 |
@count = 0 |
| 17 |
end |
| 18 |
|
| 19 |
def finish options |
| 20 |
output @count |
| 21 |
end |
| 22 |
|
| 23 |
public |
| 24 |
|
| 25 |
def text_token text, kind |
| 26 |
@count += 1 |
| 27 |
end |
| 28 |
|
| 29 |
def begin_group kind |
| 30 |
@count += 1 |
| 31 |
end |
| 32 |
alias end_group begin_group |
| 33 |
alias begin_line begin_group |
| 34 |
alias end_line begin_group |
| 35 |
|
| 36 |
end |
| 37 |
|
| 38 |
end |
| 39 |
end |