perception 0.3.3 → 0.3.4
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.txt → History.rdoc} +0 -0
- data/{License.txt → License.rdoc} +0 -0
- data/Manifest.txt +3 -3
- data/{README.txt → README.rdoc} +6 -16
- data/Rakefile.rb +11 -52
- data/lib/perception/const.rb +3 -1
- data/lib/perception/date_and_time.rb +10 -4
- data/lib/perception/logging.rb +48 -13
- data/lib/perception/numeric.rb +77 -42
- data/lib/perception/perception_main.rb +1 -1
- data/lib/perception/perception_private.rb +1 -1
- data/lib/perception/ppp.rb +103 -70
- data/lib/perception/string_spread.rb +3 -3
- data/version.rb +1 -1
- metadata +12 -12
File without changes
|
File without changes
|
data/Manifest.txt
CHANGED
data/{README.txt → README.rdoc}
RENAMED
@@ -1,8 +1,7 @@
|
|
1
|
-
# ruby encoding: utf-8
|
2
1
|
|
3
2
|
= Perception - Readable Printouts For Logs And Console
|
4
3
|
|
5
|
-
http://bklippstein.github.com/perception/
|
4
|
+
http://bklippstein.github.com/perception/frames.html
|
6
5
|
|
7
6
|
Powerfull replacement for print, puts and pp. Intuitive toolkit for simple everyday debugging.
|
8
7
|
|
@@ -21,20 +20,11 @@ use +see+ instead of pp, puts, print.
|
|
21
20
|
[] There are demos included. Run them.
|
22
21
|
|
23
22
|
|
24
|
-
==
|
25
|
-
|
26
|
-
|
27
|
-
Creative Commons Attribution-Share Alike 3.0 Germany
|
28
|
-
|
29
|
-
http://creativecommons.org/licenses/by-sa/3.0/de/deed.en
|
30
|
-
|
31
|
-
|
32
|
-
== Homepage
|
33
|
-
http://bklippstein.github.com/perception/
|
34
|
-
|
35
|
-
|
36
|
-
== Author
|
37
|
-
Björn Klippstein
|
23
|
+
== More Info
|
24
|
+
* *Documentation*: {http://bklippstein.github.com/drumherum/frames.html github.com/drumherum}
|
25
|
+
* *Source* *code*: {https://github.com/bklippstein/drumherum github.com/bklippstein/drumherum}
|
26
|
+
* *License*: {http://creativecommons.org/licenses/by-sa/3.0/de/deed.en cc-by-sa Creative Commons Attribution-Share Alike 3.0 Germany}
|
27
|
+
* *Autor*: {mailto:klippstein@klippstein.com Björn Klippstein}
|
38
28
|
|
39
29
|
|
40
30
|
== Disclaimer
|
data/Rakefile.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
-
# ü
|
3
2
|
|
4
3
|
require 'drumherum'
|
5
4
|
smart_init
|
6
5
|
require 'version'
|
7
|
-
require '
|
6
|
+
require 'yard'
|
8
7
|
require 'drumherum/rake'
|
8
|
+
YARD::Rake::YardocTask.new
|
9
9
|
|
10
10
|
Drumherum.github_username = 'bklippstein'
|
11
11
|
require 'perception'
|
@@ -22,68 +22,27 @@ $hoe = Hoe.spec Drumherum.project_name do
|
|
22
22
|
|
23
23
|
developer('Bjoern Klippstein', 'klippstein@klippstein.com')
|
24
24
|
summary = 'Beautiful and readable printouts for console and logs.'
|
25
|
-
extra_deps << ['drumherum', '>= 0.1.
|
25
|
+
extra_deps << ['drumherum', '>= 0.1.19']
|
26
26
|
extra_deps << ['kyanite', '>= 0.5.17']
|
27
27
|
extra_deps << ['highline', '>= 1.6.15']
|
28
28
|
remote_rdoc_dir = '' # Release to root only one project
|
29
|
-
urls = [[
|
29
|
+
urls = [[Drumherum.url_docs], [Drumherum.url_source]]
|
30
30
|
|
31
31
|
end
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
# ----------------------------------------------------------------------------------------------
|
36
|
-
# Documentation
|
37
|
-
#
|
38
|
-
# http://rubeh.tumblr.com/post/27622544/rake-rdoctask-with-all-of-the-options-stubbed-out
|
39
|
-
# http://www.java2s.com/Code/Ruby/Language-Basics/RDocoptionsareusedlikethisrdocoptionsnames.htm
|
40
|
-
#
|
41
|
-
|
42
|
-
remove_task 'docs'
|
43
|
-
|
44
|
-
desc "generate RDoc documentation"
|
45
|
-
Rake::RDocTask.new(:docs) do |rd|
|
46
|
-
|
47
|
-
rd.title = "#{Drumherum.project_class.to_s} #{Drumherum.project_version}"
|
48
|
-
|
49
|
-
rd.rdoc_dir = 'doc'
|
50
|
-
rd.rdoc_files.include('lib/**/*.rb')
|
51
|
-
# rd.rdoc_files.include('test/**/test_*.rb')
|
52
|
-
rd.rdoc_files.include('README.txt', 'License.txt', 'History.txt' )
|
53
|
-
|
54
|
-
rd.options += [
|
55
|
-
'--tab-width', '4',
|
56
|
-
'--main', 'README.txt',
|
57
|
-
'--show-hash', # A name of the form #name in a comment is a possible hyperlink to an instance method name. When displayed, the # is removed unless this option is specified.
|
58
|
-
'--line-numbers',
|
59
|
-
'--all',
|
60
|
-
'--charset=utf8'
|
61
|
-
]
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
35
|
|
71
36
|
# ----------------------------------------------------------------------------------------------
|
72
|
-
#
|
37
|
+
# Hide Tasks
|
73
38
|
#
|
39
|
+
|
40
|
+
hide_tasks [ :announce, :audit, :check_extra_deps, :clobber_docs, :clobber_package, :default ]
|
41
|
+
hide_tasks [ :dcov, :debug_email, :docs, :gem, :git_add, :git_commit, :git_push, :install_gem ]
|
42
|
+
hide_tasks [ :newb, :package, :post_blog, :publish_docs, :release, :release_sanity, :release_to_gemcutter ]
|
43
|
+
hide_tasks [ :repackage, :ridocs, :sleep_15, :sleep_5, :utf8, :yard, :yard_post ]
|
44
|
+
|
74
45
|
|
75
|
-
remove_task 'ridocs'
|
76
|
-
remove_task 'rdoc'
|
77
|
-
remove_task 'audit'
|
78
|
-
remove_task 'dcov'
|
79
|
-
remove_task 'debug_email'
|
80
|
-
remove_task 'debug_gem'
|
81
|
-
remove_task 'deploy'
|
82
|
-
remove_task 'deps:email'
|
83
|
-
remove_task 'install_gem'
|
84
|
-
remove_task 'multi'
|
85
|
-
remove_task 'newb'
|
86
|
-
#Dir['tasks/**/*.rake'].each { |t| load t }
|
87
46
|
|
88
47
|
|
89
48
|
|
data/lib/perception/const.rb
CHANGED
@@ -7,10 +7,15 @@ if $0 == __FILE__
|
|
7
7
|
end
|
8
8
|
|
9
9
|
|
10
|
-
module Perception
|
10
|
+
module Perception
|
11
11
|
module TimeI
|
12
12
|
|
13
|
-
|
13
|
+
|
14
|
+
# ------------------------------------------------------------------------------
|
15
|
+
# @group Using inspect_see for to_s and pretty_print
|
16
|
+
#
|
17
|
+
|
18
|
+
# @return [String]
|
14
19
|
def inspect_see(options={})
|
15
20
|
norm = options[:norm] || :iso
|
16
21
|
precision_max = 4
|
@@ -23,12 +28,13 @@ module Perception #:nodoc
|
|
23
28
|
|
24
29
|
|
25
30
|
|
26
|
-
|
31
|
+
# @return [String]
|
27
32
|
def to_s
|
28
33
|
self.inspect_see(:precision => 5)
|
29
34
|
end
|
30
35
|
|
31
36
|
|
37
|
+
# @return [String]
|
32
38
|
def pretty_print(q)
|
33
39
|
q.text(self.inspect_see(:precision => 5))
|
34
40
|
end
|
@@ -40,7 +46,7 @@ end # module Perception
|
|
40
46
|
|
41
47
|
|
42
48
|
|
43
|
-
class Time
|
49
|
+
class Time
|
44
50
|
include Perception::TimeI
|
45
51
|
end
|
46
52
|
|
data/lib/perception/logging.rb
CHANGED
@@ -7,29 +7,49 @@ if $0 == __FILE__
|
|
7
7
|
end
|
8
8
|
|
9
9
|
|
10
|
-
module Perception
|
10
|
+
module Perception
|
11
11
|
|
12
12
|
class SeeSession
|
13
13
|
|
14
|
+
# @group Logging
|
15
|
+
|
16
|
+
|
17
|
+
# Looks for a good place to save the log file,
|
18
|
+
# creates log directory & log file if necessary and
|
19
|
+
# instantiates Logger Object.
|
20
|
+
#
|
21
|
+
# Where is my logfile? Try
|
22
|
+
# see seee.logger
|
23
|
+
# =>
|
24
|
+
# <Logger:0x2a57d20
|
25
|
+
# @default_formatter = #<Logger::Formatter:0x2a57cc0 @datetime_format=nil>,
|
26
|
+
# @formatter = nil,
|
27
|
+
# @level = 0,
|
28
|
+
# @logdev = #<Logger::LogDevice:0x2a57c60 @dev=#<File:C:/Ruby-Projekte/perception/log/see.log>, @filename='C:/Ruby-Projekte/perception/log/see.log', @mutex=#<<>>, @shift_age=0, @shift_size=1048576>,
|
29
|
+
# @progname = nil>
|
30
|
+
#
|
31
|
+
# @return [Logger]
|
32
|
+
#
|
14
33
|
def logger( logdir=nil, filename='see.log' )
|
15
34
|
return @logger if @logger
|
16
|
-
require 'logger'
|
35
|
+
require 'logger' unless defined?(Logger)
|
17
36
|
|
18
37
|
# Logfile festlegen
|
19
|
-
unless logdir
|
20
|
-
|
21
|
-
logdir =
|
38
|
+
unless logdir
|
39
|
+
smart_init if Drumherum.directory_main.empty?
|
40
|
+
logdir = File.expand_path(File.join(Drumherum.directory_main, 'log'))
|
41
|
+
# puts "logdir= #{logdir} size=#{logdir.split('/').size}"
|
22
42
|
end
|
23
|
-
if ( logdir.nil? || logdir == 'test/log' )
|
43
|
+
if ( logdir.nil? || logdir.empty? || logdir == 'test/log' || logdir.split('/').size <= 2)
|
24
44
|
require 'tmpdir'
|
25
45
|
logdir = Dir::tmpdir + '/log'
|
26
46
|
end
|
47
|
+
mycaller = CallerUtils.mycaller(:skip => ['perception', 'ruby\gems', 'ruby/gems', 'test/unit'])
|
27
48
|
logfile = File.join(logdir, filename)
|
28
|
-
puts "
|
29
|
-
puts "
|
30
|
-
puts "
|
31
|
-
|
32
|
-
|
49
|
+
#puts "mycaller=#{mycaller.inspect_pp}"
|
50
|
+
#puts "logdir=#{logdir.inspect_pp}"
|
51
|
+
#puts "logfile=#{logfile.inspect_pp}"
|
52
|
+
|
33
53
|
# Erzeugen, wenn nötig
|
34
54
|
begin
|
35
55
|
# Dir erzeugen
|
@@ -40,7 +60,11 @@ module Perception #:nodoc
|
|
40
60
|
# File erzeugen
|
41
61
|
unless File.exist?(logfile)
|
42
62
|
File.open(logfile,(File::WRONLY | File::APPEND | File::CREAT))
|
43
|
-
|
63
|
+
if (mycaller.nil? || mycaller.empty?)
|
64
|
+
log_status
|
65
|
+
else
|
66
|
+
log_status("Logfile created by #{mycaller}")
|
67
|
+
end
|
44
68
|
end
|
45
69
|
#Logger erzeugen
|
46
70
|
@logger = Logger.new( logfile )
|
@@ -55,7 +79,18 @@ module Perception #:nodoc
|
|
55
79
|
end # def
|
56
80
|
|
57
81
|
|
58
|
-
|
82
|
+
# Prints a separator, the actual time and an optional message in the log file.
|
83
|
+
# Usage:
|
84
|
+
# seee.log_status "My Message"
|
85
|
+
# => (in log file)
|
86
|
+
#
|
87
|
+
# ------------------------------------------------------------------------------------------------------------------------
|
88
|
+
# 2012-10-17 Wednesday 10:47:05
|
89
|
+
# My Message
|
90
|
+
#
|
91
|
+
# @return [void]
|
92
|
+
# @param [String] message message to print
|
93
|
+
#
|
59
94
|
def log_status(message='')
|
60
95
|
status = "\n\n\n# " + ('-'*120) + "\n"
|
61
96
|
status += "# " + Time.now.inspect_see + "\n"
|
data/lib/perception/numeric.rb
CHANGED
@@ -8,10 +8,78 @@ end
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
module Perception
|
11
|
+
module Perception
|
12
12
|
|
13
13
|
module NumericI
|
14
|
+
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
# @group Slash needless digits
|
17
|
+
#
|
18
|
+
|
19
|
+
# Slash needless digits.
|
20
|
+
# Needless are digits that are
|
21
|
+
# * beyond the measurement precision or
|
22
|
+
# * not perceived by humans (instead they disturb the reception)
|
23
|
+
#
|
24
|
+
# Example:
|
25
|
+
# input (+/-) result (+) result (-) result.class
|
26
|
+
# ----------------------------------------------------------
|
27
|
+
# 12567.89 12600 -12600 Fixnum
|
28
|
+
# 1256.789 1260 -1260 Fixnum
|
29
|
+
# 123.56789 124 -124 Fixnum
|
30
|
+
# 100.01 100 -100 Fixnum
|
31
|
+
# 100.0 100 -100 Fixnum
|
32
|
+
# 99.9 99.9 -99.9 Float
|
33
|
+
# 12.0 12 -12 Fixnum
|
34
|
+
# 12 12 -12 Fixnum
|
35
|
+
# 12.56789 12.6 -12.6 Float
|
36
|
+
# 1.256789 1.26 -1.26 Float
|
37
|
+
# 1.5 1.5 -1.5 Float
|
38
|
+
# 0 0 0 Fixnum
|
39
|
+
# 0.1256789 0.126 -0.126 Float
|
40
|
+
# 0.01256789 0.0126 -0.0126 Float
|
41
|
+
# 0.001256789 0.00126 -0.00126 Float
|
42
|
+
# 0.0001256789 0.000126 -0.000126 Float
|
43
|
+
#
|
44
|
+
# @return [Numeric]
|
45
|
+
# @param [Integer] precision How many digits are significant?
|
46
|
+
def significant( precision = 3)
|
47
|
+
|
48
|
+
# sprintf mit gemischter Schreibweise
|
49
|
+
fucking_c_lib_result = sprintf("%.#{precision}g", self)
|
50
|
+
fucking_c_lib_result =~ /^(.*)e/
|
51
|
+
meine_zahl = $+ || fucking_c_lib_result
|
52
|
+
exponent = $'
|
53
|
+
# pp meine_zahl
|
54
|
+
# pp exponent
|
55
|
+
|
56
|
+
# ohne Exponent
|
57
|
+
if exponent.nil?
|
58
|
+
result = meine_zahl.to_f
|
59
|
+
if result.abs >= (10**(precision-1)) || result == result.to_i
|
60
|
+
return result.to_i
|
61
|
+
else
|
62
|
+
return result
|
63
|
+
end
|
64
|
+
|
65
|
+
# mit Exponent
|
66
|
+
else
|
67
|
+
|
68
|
+
result = meine_zahl.to_f * 10**(exponent.to_i)
|
69
|
+
if exponent[0..0] == '+'
|
70
|
+
return result.to_i
|
71
|
+
|
72
|
+
else
|
73
|
+
return result
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end # Expontent?
|
78
|
+
end # def significant
|
14
79
|
|
80
|
+
# ------------------------------------------------------------------------------
|
81
|
+
# @group Easily human readable numbers
|
82
|
+
#
|
15
83
|
|
16
84
|
# Formatiert eine Zahl so, dass sie leicht menschenlesbar wird:
|
17
85
|
# - Quasi-rechtsbündig (mit dem Komma als Bezugspunkt, abhängig von der Klassenzugehörigkeit der Zahl)
|
@@ -76,56 +144,19 @@ module Perception #:nodoc
|
|
76
144
|
end
|
77
145
|
|
78
146
|
|
79
|
-
|
80
|
-
# Wandelt in Integer um, wenn das ohne Informationsverlust möglich ist.
|
81
|
-
# Überflüssig sind Stellen, die
|
82
|
-
# * jenseits der Messprecision liegen oder
|
83
|
-
# * nicht von Menschen wahrgenommen werden (stattdessen stören sie die Rezeption)
|
84
|
-
#
|
85
|
-
def significant( precision = 3)
|
86
|
-
|
87
|
-
# sprintf mit gemischter Schreibweise
|
88
|
-
fucking_c_lib_result = sprintf("%.#{precision}g", self)
|
89
|
-
fucking_c_lib_result =~ /^(.*)e/
|
90
|
-
meine_zahl = $+ || fucking_c_lib_result
|
91
|
-
exponent = $'
|
92
|
-
# pp meine_zahl
|
93
|
-
# pp exponent
|
94
|
-
|
95
|
-
# ohne Exponent
|
96
|
-
if exponent.nil?
|
97
|
-
result = meine_zahl.to_f
|
98
|
-
if result.abs >= (10**(precision-1)) || result == result.to_i
|
99
|
-
return result.to_i
|
100
|
-
else
|
101
|
-
return result
|
102
|
-
end
|
103
|
-
|
104
|
-
# mit Exponent
|
105
|
-
else
|
106
|
-
|
107
|
-
result = meine_zahl.to_f * 10**(exponent.to_i)
|
108
|
-
if exponent[0..0] == '+'
|
109
|
-
return result.to_i
|
110
|
-
|
111
|
-
else
|
112
|
-
return result
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
end # Expontent?
|
117
|
-
end # def significant
|
147
|
+
|
118
148
|
|
119
149
|
|
120
150
|
end # module NumericI
|
121
151
|
end # module Perception
|
122
152
|
|
123
153
|
|
124
|
-
class Numeric
|
154
|
+
class Numeric
|
125
155
|
include Perception::NumericI
|
126
156
|
end
|
127
157
|
|
128
|
-
|
158
|
+
# @private
|
159
|
+
class NilClass
|
129
160
|
def size(*a); 0; end
|
130
161
|
end
|
131
162
|
|
@@ -151,11 +182,15 @@ if $0 == __FILE__ && Drumherum::loaded? then
|
|
151
182
|
|
152
183
|
when :try1 #-------------------------------------------------------------------------------
|
153
184
|
|
185
|
+
seee.out << :log
|
154
186
|
test = [12567.89, 1256.789, 123.56789, 100.01, 100.0, 99.9, 12.0, 12, 12.56789, 1.256789, 1.5, 0, 0.1256789,0.01256789,0.001256789,0.0001256789, ]
|
155
187
|
test.each do |t|
|
188
|
+
|
189
|
+
see_print "#"
|
156
190
|
see_print t.to_s.rjust(15)
|
157
191
|
see_print t.significant.to_s.rjust(15)
|
158
192
|
see_print (t * -1).significant.to_s.rjust(15)
|
193
|
+
see_print t.significant.class.to_s.rjust(15)
|
159
194
|
see_print "\n"
|
160
195
|
end
|
161
196
|
|
@@ -27,7 +27,7 @@ require 'kyanite/enumerable/structure' # Methode contentclass
|
|
27
27
|
# printing two informations in one line without destroying the structure and
|
28
28
|
# optionally slows down printing to readable speed, depending on the complexity of the output.
|
29
29
|
#
|
30
|
-
module Perception
|
30
|
+
module Perception
|
31
31
|
|
32
32
|
# Eine SeeSession-Instanz entspricht einer Session mit der Konsole.
|
33
33
|
class SeeSession
|
data/lib/perception/ppp.rb
CHANGED
@@ -7,70 +7,22 @@ if $0 == __FILE__
|
|
7
7
|
end
|
8
8
|
|
9
9
|
|
10
|
-
|
10
|
+
# patches pretty print
|
11
11
|
class PPP < PP
|
12
12
|
|
13
13
|
|
14
|
-
# ------------------------------------------------------------------------------
|
15
|
-
#
|
16
|
-
#
|
17
|
-
|
18
|
-
def self.pp(obj, out=$>, width=79 )
|
19
|
-
q = PPP.new(out, width, "\n")
|
20
|
-
q.guard_inspect_key {q.pp(obj)}
|
21
|
-
q.flush
|
22
|
-
#$pp = q
|
23
|
-
out
|
24
|
-
end
|
25
|
-
|
26
|
-
# sorgt dafür, dass Listen länger als 3 Elemente untereinander ausgegeben werden
|
27
|
-
def seplist(list, sep=nil, iter_method=:each) # :yield: element
|
28
|
-
sep = lambda { comma_newline } if (sep.kind_of?(Integer) && list.size > sep )
|
29
|
-
sep = lambda { comma_breakable } if (sep.nil? || sep.kind_of?(Integer))
|
30
|
-
first = true
|
31
|
-
list.__send__(iter_method) {|*v|
|
32
|
-
if first
|
33
|
-
first = false
|
34
|
-
else
|
35
|
-
sep.call
|
36
|
-
end
|
37
|
-
yield(*v)
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
def comma_newline
|
42
|
-
text ","
|
43
|
-
breakable('',9999)
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
# Hashes mit mehr als drei Keys werden untereinander dargestellt
|
48
|
-
def pp_hash(obj)
|
49
|
-
group(1, '{', '}') {
|
50
|
-
seplist(obj, 3, :each_pair) {|k, v|
|
51
|
-
group {
|
52
|
-
pp k
|
53
|
-
text '=>'
|
54
|
-
group(1) {
|
55
|
-
breakable ''
|
56
|
-
pp v
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
14
|
|
64
15
|
|
16
|
+
|
65
17
|
|
66
18
|
# ------------------------------------------------------------------------------
|
67
|
-
#
|
68
|
-
#
|
69
|
-
|
70
|
-
|
19
|
+
# @group Beautify: reworking the pretty print results
|
20
|
+
#
|
71
21
|
|
72
22
|
|
73
|
-
#
|
23
|
+
# reworking the pretty print results
|
24
|
+
# @return [String]
|
25
|
+
#
|
74
26
|
def self.beautify(string)
|
75
27
|
begin
|
76
28
|
result = string# .gsub!("`","'")
|
@@ -88,7 +40,9 @@ class PPP < PP
|
|
88
40
|
end # def
|
89
41
|
|
90
42
|
|
91
|
-
#
|
43
|
+
# Classifies the structure of an object for output
|
44
|
+
# @return [Symbol]
|
45
|
+
#
|
92
46
|
def self.classify_structure(object)
|
93
47
|
|
94
48
|
# Hash
|
@@ -111,8 +65,10 @@ class PPP < PP
|
|
111
65
|
|
112
66
|
|
113
67
|
|
114
|
-
# Level 2+ :
|
115
|
-
# Level 3+ :
|
68
|
+
# Level 2+ : only one line left
|
69
|
+
# Level 3+ : clip complex objects
|
70
|
+
# @return [String]
|
71
|
+
#
|
116
72
|
def self.beautify_focus_level1(string)
|
117
73
|
#return string
|
118
74
|
replaces = [[/\n/, ''], [/ {2,}/,' ']]
|
@@ -124,7 +80,9 @@ class PPP < PP
|
|
124
80
|
|
125
81
|
|
126
82
|
|
127
|
-
#
|
83
|
+
# Beautify for Objects
|
84
|
+
# @return [String]
|
85
|
+
#
|
128
86
|
def self.beautify_object(string)
|
129
87
|
result = string
|
130
88
|
result.gsub!(/= *\n */m, '=' ) # unnötigen Zeilenumbruch vermeiden
|
@@ -154,7 +112,9 @@ class PPP < PP
|
|
154
112
|
|
155
113
|
|
156
114
|
|
157
|
-
#
|
115
|
+
# Beautify for Hashes
|
116
|
+
# @return [String]
|
117
|
+
#
|
158
118
|
def self.beautify_hash(string)
|
159
119
|
result = string
|
160
120
|
result.gsub!(/=> *\n */m, '=>' ) # unnötigen Zeilenumbruch vermeiden
|
@@ -219,9 +179,11 @@ class PPP < PP
|
|
219
179
|
end
|
220
180
|
|
221
181
|
|
222
|
-
|
223
|
-
#
|
224
|
-
#
|
182
|
+
# Beautify for one-dimensional arrays
|
183
|
+
# or any object that prints like an array.
|
184
|
+
# In front of the brackets there are identifier allowed, eg WP [1, 2, 3]
|
185
|
+
# @return [String]
|
186
|
+
#
|
225
187
|
def self.beautify_array_1dim(string)
|
226
188
|
return string
|
227
189
|
# tabstops = result[1..-2].analyze_columns( :level_start => 0,
|
@@ -240,9 +202,10 @@ class PPP < PP
|
|
240
202
|
end
|
241
203
|
|
242
204
|
|
243
|
-
|
244
|
-
#
|
245
|
-
#
|
205
|
+
# Beautify for two-dimensional arrays -
|
206
|
+
# very dirty.
|
207
|
+
# @return [String]
|
208
|
+
#
|
246
209
|
def self.beautify_array_2dim(string)
|
247
210
|
result = string
|
248
211
|
|
@@ -296,9 +259,15 @@ class PPP < PP
|
|
296
259
|
end
|
297
260
|
|
298
261
|
|
262
|
+
|
263
|
+
|
264
|
+
# Beautify for complex objects.
|
265
|
+
#
|
299
266
|
# Mehrere Ausgaben in einer Zeile.
|
300
267
|
# Die einzelnen Ausgaben liegen als Array vor.
|
301
268
|
# Das Ergebnis soll aber nicht wie ein Array ausssehen.
|
269
|
+
# @return [String]
|
270
|
+
#
|
302
271
|
def self.beautify_multi(string)
|
303
272
|
result = string
|
304
273
|
result = beautify_focus_level1(result)
|
@@ -320,20 +289,78 @@ class PPP < PP
|
|
320
289
|
|
321
290
|
|
322
291
|
|
292
|
+
# ------------------------------------------------------------------------------
|
293
|
+
# @group Pretty Print Patches
|
294
|
+
#
|
295
|
+
|
296
|
+
|
297
|
+
def self.pp(obj, out=$>, width=79 )
|
298
|
+
q = PPP.new(out, width, "\n")
|
299
|
+
q.guard_inspect_key {q.pp(obj)}
|
300
|
+
q.flush
|
301
|
+
#$pp = q
|
302
|
+
out
|
303
|
+
end
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
# ensures that lists with more than three elements are displayed line by line
|
308
|
+
def seplist(list, sep=nil, iter_method=:each) # :yield: element
|
309
|
+
sep = lambda { comma_newline } if (sep.kind_of?(Integer) && list.size > sep )
|
310
|
+
sep = lambda { comma_breakable } if (sep.nil? || sep.kind_of?(Integer))
|
311
|
+
first = true
|
312
|
+
list.__send__(iter_method) {|*v|
|
313
|
+
if first
|
314
|
+
first = false
|
315
|
+
else
|
316
|
+
sep.call
|
317
|
+
end
|
318
|
+
yield(*v)
|
319
|
+
}
|
320
|
+
end
|
321
|
+
|
322
|
+
|
323
|
+
def comma_newline
|
324
|
+
text ","
|
325
|
+
breakable('',9999)
|
326
|
+
end
|
327
|
+
|
328
|
+
|
323
329
|
|
330
|
+
# hashes with more than three keys are displayed line by line
|
331
|
+
def pp_hash(obj)
|
332
|
+
group(1, '{', '}') {
|
333
|
+
seplist(obj, 3, :each_pair) {|k, v|
|
334
|
+
group {
|
335
|
+
pp k
|
336
|
+
text '=>'
|
337
|
+
group(1) {
|
338
|
+
breakable ''
|
339
|
+
pp v
|
340
|
+
}
|
341
|
+
}
|
342
|
+
}
|
343
|
+
}
|
344
|
+
end
|
324
345
|
|
325
346
|
|
326
347
|
|
327
348
|
end # class
|
328
349
|
|
329
350
|
|
330
|
-
class String
|
351
|
+
class String
|
352
|
+
|
353
|
+
# @return [String]
|
331
354
|
def pretty_print(q)
|
332
355
|
q.text "'#{self}'"
|
333
356
|
end
|
357
|
+
|
334
358
|
end
|
335
359
|
|
336
|
-
|
360
|
+
|
361
|
+
class Set
|
362
|
+
|
363
|
+
# @return [String]
|
337
364
|
def pretty_print(q)
|
338
365
|
q.group(1, '{', '}') {
|
339
366
|
q.seplist(self) {|v|
|
@@ -342,13 +369,17 @@ class Set # :nodoc:
|
|
342
369
|
}
|
343
370
|
end
|
344
371
|
|
372
|
+
|
345
373
|
def pretty_print_cycle(q)
|
346
374
|
q.text(empty? ? '{}' : '{...}')
|
347
375
|
end
|
376
|
+
|
348
377
|
end
|
349
378
|
|
350
379
|
|
351
|
-
class Dictionary
|
380
|
+
class Dictionary
|
381
|
+
|
382
|
+
# @return [String]
|
352
383
|
def inspect
|
353
384
|
ary = []
|
354
385
|
each {|k,v| ary << k.inspect + "=>" + v.inspect}
|
@@ -357,7 +388,9 @@ class Dictionary # :nodoc:
|
|
357
388
|
end
|
358
389
|
|
359
390
|
|
360
|
-
class Dictionary
|
391
|
+
class Dictionary
|
392
|
+
|
393
|
+
# @return [String]
|
361
394
|
def pretty_print(q)
|
362
395
|
q.pp_hash self
|
363
396
|
end
|
@@ -8,8 +8,8 @@ end
|
|
8
8
|
require 'kyanite/array_of_enumerables'
|
9
9
|
|
10
10
|
|
11
|
-
module Perception
|
12
|
-
module StringSpreadI
|
11
|
+
module Perception
|
12
|
+
module StringSpreadI
|
13
13
|
|
14
14
|
|
15
15
|
def analyze_columns(options={})
|
@@ -129,7 +129,7 @@ module Perception #:nodoc
|
|
129
129
|
end # module
|
130
130
|
end # module
|
131
131
|
|
132
|
-
class String
|
132
|
+
class String
|
133
133
|
include Perception::StringSpreadI
|
134
134
|
end
|
135
135
|
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perception
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: drumherum
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.1.
|
21
|
+
version: 0.1.19
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.1.
|
29
|
+
version: 0.1.19
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: kyanite
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,17 +97,17 @@ email:
|
|
97
97
|
executables: []
|
98
98
|
extensions: []
|
99
99
|
extra_rdoc_files:
|
100
|
-
- History.
|
101
|
-
- License.
|
100
|
+
- History.rdoc
|
101
|
+
- License.rdoc
|
102
102
|
- Manifest.txt
|
103
|
-
- README.
|
103
|
+
- README.rdoc
|
104
104
|
files:
|
105
105
|
- console.rb
|
106
|
-
- History.
|
107
|
-
- License.
|
106
|
+
- History.rdoc
|
107
|
+
- License.rdoc
|
108
108
|
- Manifest.txt
|
109
109
|
- Rakefile.rb
|
110
|
-
- README.
|
110
|
+
- README.rdoc
|
111
111
|
- version.rb
|
112
112
|
- demo/demo_pp.rb
|
113
113
|
- demo/demo_system_info.rb
|
@@ -128,12 +128,12 @@ files:
|
|
128
128
|
- test/test_numeric.rb
|
129
129
|
- test/test_ppp.rb
|
130
130
|
- .gemtest
|
131
|
-
homepage:
|
131
|
+
homepage: http://bklippstein.github.com/perception/frames.html
|
132
132
|
licenses: []
|
133
133
|
post_install_message:
|
134
134
|
rdoc_options:
|
135
135
|
- --main
|
136
|
-
- README.
|
136
|
+
- README.rdoc
|
137
137
|
require_paths:
|
138
138
|
- lib
|
139
139
|
required_ruby_version: !ruby/object:Gem::Requirement
|