diff options
author | murphy <murphy@rubychan.de> | 2006-10-17 10:10:35 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2006-10-17 10:10:35 +0000 |
commit | 5e0d6d97bf4676ab1c1ca9b06590dd774d263b0d (patch) | |
tree | db433d0109b087ffaa3f25fece64ea62c7481e8e /sample/encoder.rb | |
parent | 975a2fd6ea64529d993bc1412899fad386ff02ea (diff) | |
download | coderay-5e0d6d97bf4676ab1c1ca9b06590dd774d263b0d.tar.gz |
Renamed demo files (trim demo_ prefix).
Diffstat (limited to 'sample/encoder.rb')
-rw-r--r-- | sample/encoder.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/sample/encoder.rb b/sample/encoder.rb new file mode 100644 index 0000000..267676b --- /dev/null +++ b/sample/encoder.rb @@ -0,0 +1,39 @@ +require 'coderay'
+
+SAMPLE = "puts 17 + 4\n"
+puts 'Encoders Demo: ' + SAMPLE
+scanner = CodeRay::Scanners[:ruby].new SAMPLE
+encoder = CodeRay::Encoders[:statistic].new
+
+tokens = scanner.tokenize
+stats = encoder.encode_tokens tokens
+
+puts
+puts 'Statistic:'
+puts stats
+
+# alternative 1
+tokens = CodeRay.scan SAMPLE, :ruby
+encoder = CodeRay.encoder(:tokens)
+textual = encoder.encode_tokens tokens
+puts
+puts 'Original text:'
+puts textual
+
+# alternative 2
+yaml = CodeRay.encoder(:yaml).encode SAMPLE, :ruby
+puts
+puts 'YAML:'
+puts yaml
+
+# alternative 3
+BIGSAMPLE = SAMPLE * 100
+dump = CodeRay.scan(BIGSAMPLE, :ruby).dump
+puts
+puts 'Dump:'
+p dump
+puts 'compressed: %d byte < %d byte' % [dump.size, BIGSAMPLE.size]
+
+puts
+puts 'Undump:'
+puts dump.undump.statistic
|