perception 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.rdoc CHANGED
@@ -1,3 +1,5 @@
1
+ == 0.3.5 2012-10-19
2
+ * Yard documentation
1
3
 
2
4
  == 0.3.2 2012-10-08
3
5
  * smart_init
data/Manifest.txt CHANGED
@@ -5,9 +5,11 @@ Manifest.txt
5
5
  Rakefile.rb
6
6
  README.rdoc
7
7
  version.rb
8
- demo/demo_pp.rb
9
- demo/demo_system_info.rb
10
- demo/demo_zz.rb
8
+ demo/demo1.rb
9
+ demo/demo2.rb
10
+ demo/demo3.rb
11
+ demo/Example_Output_1.rb
12
+ demo/Example_Output_2.rb
11
13
  init.rb
12
14
  lib/perception.rb
13
15
  lib/perception/const.rb
data/README.rdoc CHANGED
@@ -1,23 +1,39 @@
1
+ = Perception: Human perceptible printouts
2
+ http://bklippstein.github.com/perception/frames.html
1
3
 
2
- = Perception - Readable Printouts For Logs And Console
4
+ Welcome to Perception. It's a intuitive toolkit for simple everyday debugging.
5
+ Perception offers a powerfull replacement for print, puts and pp and is an alternative to Awesome Print.
6
+
7
+ You get auto-intended and structured output on your console without any configuration.
8
+
9
+ Perception also offers temporary printouts (overwritten by the next print), printing two informations
10
+ in one line without destroying the structure and optionally slows down printing to readable speed,
11
+ depending on the complexity of the output.
3
12
 
4
- http://bklippstein.github.com/perception/frames.html
5
13
 
6
- Powerfull replacement for print, puts and pp. Intuitive toolkit for simple everyday debugging.
14
+ == see: Powerfull replacement for print, puts and pp
15
+ {include:Object#see}
16
+ More: {Object#see}
7
17
 
8
- You get auto-intended and structured output on your console without any configuration.
18
+ == log: use logging without configuration
19
+ You can use log instead of see, the formating is the same.
20
+ The log directory and the logfile are automatically created if necessary.
9
21
 
10
- Perception also offers temporary printouts (overwritten by the next print). So you can print
11
- two informations in one place without destroying the structure.
22
+ More: {Object#log log}, {Object#rawlog rawlog}, {Perception::SeeSession#logger seee.logger}
12
23
 
13
- Perception optionally slows down printing to readable speed, depending on the complexity of the output.
24
+ == Intelligent round: slash needless digits
25
+ {include:Perception::NumericI#significant}
26
+ More: {Perception::NumericI#significant significant}
14
27
 
28
+ == Easily human readable numbers
29
+ {include:Perception::NumericI#inspect_see}
30
+ More: {Perception::NumericI#inspect_see inspect_see}
15
31
 
16
32
 
17
- == Usage
18
- require 'perception'
19
- use +see+ instead of pp, puts, print.
20
- [] There are demos included. Run them.
33
+ == Examples and Demos
34
+ * {file:demo/Example_Output_1.rb}
35
+ * {file:demo/Example_Output_2.rb}
36
+ * {file:demo/demo3.rb} (interactive)
21
37
 
22
38
 
23
39
  == More Info
@@ -0,0 +1,183 @@
1
+ # See source code and run it for yourself: {file:demo/demo1.rb}
2
+
3
+
4
+ Basic Types
5
+ ===========
6
+
7
+
8
+ 1dim Arrays are printed verticaly, if their size is not too big:
9
+
10
+
11
+ ['this', 'is', 'an', 'array', '1']
12
+ ['this', 'is', 'another', 'array', '2']
13
+ ['complex array', [1, 2, 3], {:key=>:value, :love=>:baby}, 4.0, :four]
14
+ []
15
+
16
+
17
+ Other Objects:
18
+ ordinary string (without "")
19
+ (next one is empty)
20
+ empty
21
+ 1
22
+ 2
23
+ 3
24
+ nil
25
+ true
26
+ false
27
+ :a_symbol
28
+
29
+
30
+
31
+
32
+
33
+
34
+ 2dimensional Arrays
35
+ ===================
36
+
37
+
38
+ 2dim Arrays are printed like a table:
39
+
40
+
41
+ [['this', 'is', 'an', 'array', '1'],
42
+ ['this', 'is', 'another', 'array', '2'],
43
+ ['and', 'this', 'is', 'another', :tree],
44
+ ['no', {:key=>:value}, 'just', 'another', 'array']]
45
+
46
+
47
+
48
+
49
+ [['one', 'a', 'b', 'c'],
50
+ ['two', 'long_longlong_long_long', 'also_long, also_long, also_long_also', 'hallo'],
51
+ ['three', 'also_long, also_long, also_long_also', 'also_long, also_long, also_long_also', 'long_longlong_long_long']]
52
+
53
+
54
+
55
+
56
+
57
+
58
+ Nested Objects
59
+ ==============
60
+
61
+
62
+ Nested objects reveal their structure. Lower hierary levels may be reduced for this:
63
+
64
+
65
+ #<Perception::SeeSession:0x2aa0cc8
66
+ @call_stack_last = 5,
67
+ @call_stack_now = 6,
68
+ @cursor_now = 1148,
69
+ @delayed_clear = false,
70
+ @delayed_newlines = 0,
71
+ @indent = false,
72
+ @level = 1,
73
+ @logger = #<Logger:0x2ae80c8 @default_formatter=#<>, @formatter=nil, @level=0, @logdev=#<<><<>>>, @progname=nil>,
74
+ @method_last = :puts,
75
+ @method_now = :pp,
76
+ @out = {:console, :log},
77
+ @speed = nil,
78
+ @string_last = '
79
+ ',
80
+ @time_last = 2012-10-18 Thursday 23:27:03>
81
+
82
+
83
+ The Logger has been reduced. This is its detail view:
84
+
85
+
86
+ #<Logger:0x2ae80c8
87
+ @default_formatter = #<Logger::Formatter:0x2ae8020 @datetime_format=nil>,
88
+ @formatter = nil,
89
+ @level = 0,
90
+ @logdev = #<Logger::LogDevice:0x2af3750 @dev=#<File:C:/Ruby-Projekte/perception/log/see.log>, @filename='C:/Ruby-Projekte/perception/log/see.log', @mutex=#<<>>, @shift_age=0, @shift_size=1048576>,
91
+ @progname = nil>
92
+
93
+
94
+
95
+
96
+ PrettyPrint shows all at one, but its very hard to read:
97
+
98
+
99
+ PrettyPrint shows all at one, but its very hard to read:
100
+
101
+ #<Perception::SeeSession:0x2aa0cc8
102
+ @call_stack_last=5,
103
+ @call_stack_now=5,
104
+ @cursor_now=2196,
105
+ @delayed_clear=false,
106
+ @delayed_newlines=1,
107
+ @indent=false,
108
+ @level=1,
109
+ @logger=
110
+ #<Logger:0x2ae80c8
111
+ @default_formatter=#<Logger::Formatter:0x2ae8020 @datetime_format=nil>,
112
+ @formatter=nil,
113
+ @level=0,
114
+ @logdev=
115
+ #<Logger::LogDevice:0x2af3750
116
+ @dev=#<File:C:/Ruby-Projekte/perception/log/see.log>,
117
+ @filename='C:/Ruby-Projekte/perception/log/see.log',
118
+ @mutex=
119
+ #<Logger::LogDevice::LogDeviceMutex:0x2af3738
120
+ @mon_count=0,
121
+ @mon_mutex=#<Mutex:0x2af36c0>,
122
+ @mon_owner=nil>,
123
+ @shift_age=0,
124
+ @shift_size=1048576>,
125
+ @progname=nil>,
126
+ @method_last=:puts,
127
+ @method_now=:puts,
128
+ @out={:console, :log},
129
+ @speed=nil,
130
+ @string_last='',
131
+ @time_last=2012-10-18 Thursday 23:27:03>
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+ Hash
140
+ ====
141
+
142
+
143
+ {:this=>:hash, :in=>:one, :see=>'short hash in one line'}
144
+
145
+
146
+
147
+
148
+ {:this => :hash,
149
+ :size => '> 3',
150
+ :see => 'longer hash in multiple lines',
151
+ :another_key => 'another value'}
152
+
153
+
154
+
155
+
156
+ {:hash => true,
157
+ :init => true,
158
+ :nil => nil,
159
+ :symbol => :symbol,
160
+ :text => 'text',
161
+ :array => [1, 2, 3],
162
+ :integer => 1,
163
+ :string => 'hallo',
164
+ :nochn_hash => {:key=>:value, :bla=>:blubb, :array=>[:a, :b, :c], :another_key=>'another value'}}
165
+
166
+
167
+
168
+
169
+
170
+
171
+ Dictionary
172
+ ==========
173
+
174
+
175
+ {:a_dictionary => true,
176
+ :b_init => true,
177
+ :c_symbol => :symbol,
178
+ :d_array => [1, 2, 3],
179
+ :e_integer => 1,
180
+ :f_string => 'hallo',
181
+ :g_subdictionary => {:a=>:value, :b=>'blubb', :c=>2, :d=>[:a, :b, :c], :e=>{:key=>:value}, :f=>'hallo'}}
182
+
183
+
@@ -0,0 +1,63 @@
1
+
2
+ see (Perception)
3
+ ================
4
+
5
+ see RbConfig::CONFIG
6
+ =>
7
+ {'DESTDIR' => 'C:',
8
+ 'MAJOR' => '1',
9
+ 'MINOR' => '9',
10
+ 'TEENY' => '1',
11
+ 'PATCHLEVEL' => '125',
12
+ 'INSTALL' => '/usr/bin/install -c',
13
+ 'EXEEXT' => '.exe',
14
+ 'prefix' => 'C:/Rails/Ruby1.9.3',
15
+ 'ruby_install_name' => 'ruby',
16
+ 'RUBY_INSTALL_NAME' => 'ruby',
17
+ 'RUBY_SO_NAME' => 'msvcrt-ruby191',
18
+ 'exec' => 'exec',
19
+ 'ruby_pc' => 'ruby-1.9.pc',
20
+ 'PACKAGE' => 'ruby',
21
+ 'BUILTIN_TRANSSRCS' => ' newline.c',
22
+ 'USE_RUBYGEMS' => 'YES',
23
+ 'MANTYPE' => 'man',
24
+ 'NROFF' => '/bin/false',
25
+ 'vendorhdrdir' => 'C:/Rails/Ruby1.9.3/include/ruby-1.9.1/vendor_ruby',
26
+ 'sitehdrdir' => 'C:/Rails/Ruby1.9.3/include/ruby-1.9.1/site_ruby',
27
+ 'rubyhdrdir' => 'C:/Rails/Ruby1.9.3/include/ruby-1.9.1',
28
+ 'UNIVERSAL_INTS' => '',
29
+ ...
30
+
31
+
32
+ pp (PrettyPrint)
33
+ ================
34
+
35
+ pp RbConfig::CONFIG
36
+ =>
37
+ {'DESTDIR'=>'C:',
38
+ 'MAJOR'=>'1',
39
+ 'MINOR'=>'9',
40
+ 'TEENY'=>'1',
41
+ 'PATCHLEVEL'=>'125',
42
+ 'INSTALL'=>'/usr/bin/install -c',
43
+ 'EXEEXT'=>'.exe',
44
+ 'prefix'=>'C:/Rails/Ruby1.9.3',
45
+ 'ruby_install_name'=>'ruby',
46
+ 'RUBY_INSTALL_NAME'=>'ruby',
47
+ 'RUBY_SO_NAME'=>'msvcrt-ruby191',
48
+ 'exec'=>'exec',
49
+ 'ruby_pc'=>'ruby-1.9.pc',
50
+ 'PACKAGE'=>'ruby',
51
+ 'BUILTIN_TRANSSRCS'=>' newline.c',
52
+ 'USE_RUBYGEMS'=>'YES',
53
+ 'MANTYPE'=>'man',
54
+ 'NROFF'=>'/bin/false',
55
+ 'vendorhdrdir'=>'C:/Rails/Ruby1.9.3/include/ruby-1.9.1/vendor_ruby',
56
+ 'sitehdrdir'=>'C:/Rails/Ruby1.9.3/include/ruby-1.9.1/site_ruby',
57
+ 'rubyhdrdir'=>'C:/Rails/Ruby1.9.3/include/ruby-1.9.1',
58
+ 'UNIVERSAL_INTS'=>'',
59
+ ...
60
+
61
+
62
+
63
+
@@ -1,5 +1,9 @@
1
1
  # ruby encoding: utf-8
2
- # ü
2
+ #
3
+ # This generates Example_Output_1.
4
+ # --------------------------------
5
+ #
6
+ #
3
7
  if $0 == __FILE__
4
8
  require 'drumherum'
5
9
  smart_init
@@ -13,7 +17,7 @@ module Perception #:nodoc
13
17
  @@initialized_count = 0
14
18
 
15
19
  def initialize( announce_first=true )
16
- #seee.out << :log
20
+ seee.out << :log
17
21
  @@initialized_count += 1
18
22
  return if (@@initialized_count == 1 && !announce_first)
19
23
  #seee.slow!(0.5)
@@ -32,18 +36,21 @@ module Perception #:nodoc
32
36
  # wait_for_key('Press any key to start')
33
37
 
34
38
 
35
- end # def
39
+ end # defü
36
40
 
37
41
 
38
42
 
39
43
  # Printing basic types
40
44
  def demo_see_basic_types
41
- see '1dim Arrays:'
42
- seee.indent!
45
+ see '1dim Arrays are printed verticaly, if their size is not too big:'
43
46
  see
47
+ seee.left!
48
+ see a=['this','is','an','array','1']
49
+ see b=['this','is','another','array','2']
50
+ see d=['complex array', [1,2,3], {:key => :value, :love => :baby}, 4.0, :four]
51
+ see []
44
52
  see
45
53
  see 'Other Objects:'
46
- see []
47
54
  see 'ordinary string (without "")'
48
55
  see '(next one is empty)'
49
56
  see ''
@@ -55,17 +62,30 @@ module Perception #:nodoc
55
62
  see false
56
63
  see :a_symbol
57
64
 
58
- see ['complex array', [1,2,3], {:key => :value, :love => :baby}, 3.0 , '']
59
65
  end # def
60
66
 
61
67
 
62
68
  def demo_see_pp_object
69
+ see 'Nested objects reveal their structure. Lower hierary levels may be reduced for this:'
70
+ see
63
71
  seee.logger
64
72
  see seee
73
+ see
74
+ see 'The Logger has been reduced. This is it''s detail view:'
75
+ see
76
+ see seee.logger
77
+ see
78
+ see
79
+ see 'PrettyPrint shows all at one, but it''s very hard to read:'
80
+ see
81
+ pp seee
65
82
  end
66
83
 
67
84
 
85
+
68
86
  def demo_see_pp_array
87
+ see '2dim Arrays are printed like a table:'
88
+ see
69
89
  @array1 = []
70
90
  @array1 << ['this','is','an','array','1']
71
91
  @array1 << ['this','is','another','array','2']
@@ -129,13 +149,14 @@ module Perception #:nodoc
129
149
 
130
150
 
131
151
  def self.see_all_demos
132
- Perception::DemoSee.new('PrettyPrint Array').demo_see_pp_array
133
- Perception::DemoSee.new('PrettyPrint Object').demo_see_pp_object
134
- Perception::DemoSee.new('PrettyPrint Hash').demo_see_pp_hash
135
- Perception::DemoSee.new('PrettyPrint Dictionary').demo_see_pp_dictionary
152
+ Perception::DemoSee.new('Basic Types').demo_see_basic_types
153
+ Perception::DemoSee.new('2dimensional Arrays').demo_see_pp_array
154
+ Perception::DemoSee.new('Nested Objects').demo_see_pp_object
155
+ Perception::DemoSee.new('Hash').demo_see_pp_hash
156
+ Perception::DemoSee.new('Dictionary').demo_see_pp_dictionary
136
157
 
137
158
 
138
- Perception::DemoSee.new('PrettyPrint div').demo_see_basic_types
159
+
139
160
 
140
161
  end
141
162
 
@@ -147,6 +168,7 @@ end # class
147
168
 
148
169
  if $0 == __FILE__ then
149
170
 
171
+ # seee.out << :log
150
172
  Perception::DemoSee.see_all_demos
151
173
 
152
174
 
data/demo/demo2.rb ADDED
@@ -0,0 +1,37 @@
1
+ # ruby encoding: utf-8
2
+ # ü
3
+ if $0 == __FILE__
4
+ require 'drumherum'
5
+ smart_init
6
+ require 'perception'
7
+ end
8
+
9
+ require 'rbconfig'
10
+ # seee.out << :log
11
+ see "see RbConfig::CONFIG"
12
+ see "=>"
13
+ see RbConfig::CONFIG
14
+ see
15
+ see
16
+ see "---------------------------------------------------------------------------------------"
17
+ see
18
+ # see "pp RbConfig::CONFIG"
19
+ # see "=>"
20
+ # pp RbConfig::CONFIG
21
+
22
+
23
+
24
+
25
+
26
+ # require 'awesome_print'
27
+ # ap RbConfig::CONFIG
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
data/demo/demo3.rb ADDED
@@ -0,0 +1,201 @@
1
+ # ruby encoding: utf-8
2
+ # ü
3
+ if $0 == __FILE__
4
+ require 'drumherum'
5
+ smart_init
6
+ require 'perception'
7
+ end
8
+
9
+
10
+ module Perception #:nodoc
11
+
12
+ class DemoSee
13
+ @@initialized_count = 0
14
+
15
+ def initialize( announce_first=true )
16
+ #seee.out << :log
17
+ @@initialized_count += 1
18
+ return if (@@initialized_count == 1 && !announce_first)
19
+ #seee.slow!(0.5)
20
+ seee.left!
21
+ #seee.indent!
22
+ see ("\n" * 5) if @@initialized_count > 1
23
+
24
+ if announce_first.kind_of?(String)
25
+ see announce_first
26
+ see '='*announce_first.size
27
+ else
28
+ see "Perception Demo ##{@@initialized_count}"
29
+ see "=================="
30
+ end
31
+ see
32
+ wait_for_key('Press any key to start')
33
+ end # def
34
+
35
+
36
+
37
+ def demo_level
38
+ seee.slow!
39
+ see "The printout is automaticaly indented. This is the printout of a nested structure of #see's:"
40
+ see
41
+ see
42
+ seee.indent!
43
+ sub_demo_level
44
+ see
45
+ see
46
+ #wait_for_key
47
+ see 'You can force left printout with seee.left!. Reactivate indention with seee.indent!.'
48
+ seee.left!
49
+ see
50
+ see
51
+ sub_demo_level
52
+ end
53
+
54
+
55
+ def sub_demo_level
56
+ see "Hello world. This is level zero. "
57
+ (1..1).each do
58
+ see "This is the beginning of level one."
59
+ 1.downto(1) do
60
+ see "This is the beginning of level two."
61
+ 1.upto(1) do
62
+ see "This is the beginning of level three."
63
+ 1.times do
64
+ see "This is the beginning of level four."
65
+ see "This is the end of level four."
66
+ end
67
+ see "This is the end of level three."
68
+ end
69
+ see "This is the end of level two."
70
+ end
71
+ see "This is the end of level one."
72
+ end
73
+ see "This is level zero again. Bye. "
74
+ end # def
75
+
76
+
77
+
78
+
79
+
80
+
81
+ # slow printing
82
+ def demo_see_slowdown1
83
+ seee.slow!
84
+ see "You can slow down printing with seee.slow!"
85
+ see
86
+ see 'This is a string'
87
+ see 'and here we have a longer one.'
88
+ see 'so we need even longeer strings, but they all have to be different.'
89
+ see '#see has forgotten the first string. So I will tell him again: This is a string. and here we have a longer one. '
90
+ see 'In slow mode #see waits for you to read the lines. More words, longer waiting.'
91
+ see 'short prints...'
92
+ see '...short waiting.'
93
+ see 'short prints...'
94
+ see '...short waiting.'
95
+ see
96
+ see
97
+ string = 'This string is getting longer.'
98
+ (1..10).each do |i|
99
+ see string
100
+ string += ' But it repeats.'
101
+ end
102
+ see
103
+ see '#see only counts those words you have to read.'
104
+ see
105
+ see
106
+ see 'You can choose the speed. seee.slow!(0.5) is faster: '
107
+
108
+ wait_for_key
109
+ see
110
+ seee.slow!(0.5)
111
+ see 'This is a string'
112
+ see 'and here we have a longer one.'
113
+ see 'so we need even longeer strings, but they all have to be different.'
114
+ see '#see has forgotten the first string. So I will tell him again: This is a string. and here we have a longer one. '
115
+ see 'In slow mode #see waits for you to read the lines. More words, longer waiting.'
116
+ see 'short prints...'
117
+ see '...short waiting.'
118
+ see '...short waiting.'
119
+ string = 'This string is getting longer.'
120
+ (1..10).each do |i|
121
+ see string
122
+ string += ' But it repeats.'
123
+ end
124
+ see
125
+ see '#see only counts those words you have to read.'
126
+ see
127
+ end
128
+
129
+
130
+
131
+
132
+ # Simple benchmarking
133
+ def demo_bench
134
+ see 'You always get the time since last print with seee.bench.'
135
+ see 'You can use this for simple benchmarking:'
136
+ see "I'm counting to 50 000 000, please wait."
137
+ 50000000.downto(0) {}
138
+ see "it took #{seee.bench} seconds."
139
+
140
+ end
141
+
142
+
143
+ # temporary printing
144
+ def demo_see_temp_and_clear_last
145
+ seee.slow!
146
+ see_print "countdown: "
147
+ 10.downto(0) do |i|
148
+ see_temp i
149
+ end
150
+ see 'finished!'
151
+ sleep 1
152
+ seee.clear!
153
+ see 'You can clear the last print with seee.clear!'
154
+ see 'And you can print temporary informations with see_temp'
155
+ end
156
+
157
+
158
+
159
+ # print two informations on one line
160
+ def demo_alternate_see
161
+ see ['horst.maierman','PW-AEerSDFs', 'addional', 'information', :one]
162
+ see ['claudia.hoppe','27546522sdfgdz3s', 'addional', 'information', :two]
163
+ see ['nadja.hirsch','Minnie', 'addional', 'information', :three]
164
+ seee.flash! ' Bad password! '
165
+ see ['tom.flupper','Gs3Kkd2', 'addional', 'information', :five]
166
+ see ['anna.chevrezonk','2sdtg&fH', 'addional', 'information', :six]
167
+ see ['hardy.schwarzer','dfjhRfDdtis', 'addional', 'information', :seven]
168
+ end
169
+
170
+
171
+
172
+
173
+ def self.see_all_demos
174
+ Perception::DemoSee.new('Automatic Indenting').demo_level
175
+ Perception::DemoSee.new('Slowing down').demo_see_slowdown1
176
+ Perception::DemoSee.new('Simple Benchmarking').demo_bench
177
+ Perception::DemoSee.new('Progress Indicator').demo_see_temp_and_clear_last
178
+ Perception::DemoSee.new('Two layers of information in one line').demo_alternate_see
179
+ end
180
+
181
+
182
+
183
+ end # class
184
+ end # class
185
+
186
+
187
+ if $0 == __FILE__ then
188
+
189
+ Perception::DemoSee.see_all_demos
190
+
191
+ end
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
@@ -8,6 +8,8 @@ end
8
8
 
9
9
 
10
10
  module Perception
11
+
12
+
11
13
  module TimeI
12
14
 
13
15