pp 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pp.rb +36 -5
- data/pp.gemspec +9 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05c96009c03ef3d1fb5542a17f2833a93b128a7579380a4c608384fc6232d5a7
|
4
|
+
data.tar.gz: 629c3161e24420959ea1946d612f22ce4b73694f7e5c805499fb166f75cd9de8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98484471668309f5a8822bc9206cff58534431274db6d0cb828876417fdf4f4e932f61894d613aced33246ee168b85c4d6c2d8d38faaf5bdb0fae6fcea55bc59
|
7
|
+
data.tar.gz: 4fd410d4b90723eaaf32e221d219ee88db428ecc7b133f0b873aa9625045bc7e83d55e04edeb0d715ed3d9a32d71cb2ae5d0aaad4ebf981f05424a4dfbfebb5c
|
data/lib/pp.rb
CHANGED
@@ -46,6 +46,7 @@ require 'prettyprint'
|
|
46
46
|
#
|
47
47
|
# To define a customized pretty printing function for your classes,
|
48
48
|
# redefine method <code>#pretty_print(pp)</code> in the class.
|
49
|
+
# Note that <code>require 'pp'</code> is needed before redefining <code>#pretty_print(pp)</code>.
|
49
50
|
#
|
50
51
|
# <code>#pretty_print</code> takes the +pp+ argument, which is an instance of the PP class.
|
51
52
|
# The method uses #text, #breakable, #nest, #group and #pp to print the
|
@@ -61,6 +62,19 @@ require 'prettyprint'
|
|
61
62
|
# Tanaka Akira <akr@fsij.org>
|
62
63
|
|
63
64
|
class PP < PrettyPrint
|
65
|
+
|
66
|
+
VERSION = "0.5.0"
|
67
|
+
|
68
|
+
# Returns the usable width for +out+.
|
69
|
+
# As the width of +out+:
|
70
|
+
# 1. If +out+ is assigned to a tty device, its width is used.
|
71
|
+
# 2. Otherwise, or it could not get the value, the +COLUMN+
|
72
|
+
# environment variable is assumed to be set to the width.
|
73
|
+
# 3. If +COLUMN+ is not set to a non-zero number, 80 is assumed.
|
74
|
+
#
|
75
|
+
# And finally, returns the above width value - 1.
|
76
|
+
# * This -1 is for Windows command prompt, which moves the cursor to
|
77
|
+
# the next line if it reaches the last column.
|
64
78
|
def PP.width_for(out)
|
65
79
|
begin
|
66
80
|
require 'io/console'
|
@@ -74,7 +88,8 @@ class PP < PrettyPrint
|
|
74
88
|
# +width+ columns in width.
|
75
89
|
#
|
76
90
|
# If +out+ is omitted, <code>$></code> is assumed.
|
77
|
-
# If +width+ is omitted,
|
91
|
+
# If +width+ is omitted, the width of +out+ is assumed (see
|
92
|
+
# width_for).
|
78
93
|
#
|
79
94
|
# PP.pp returns +out+.
|
80
95
|
def PP.pp(obj, out=$>, width=width_for(out))
|
@@ -405,6 +420,26 @@ class Struct # :nodoc:
|
|
405
420
|
end
|
406
421
|
end
|
407
422
|
|
423
|
+
class Data # :nodoc:
|
424
|
+
def pretty_print(q) # :nodoc:
|
425
|
+
q.group(1, sprintf("#<data %s", PP.mcall(self, Kernel, :class).name), '>') {
|
426
|
+
q.seplist(PP.mcall(self, Data, :members), lambda { q.text "," }) {|member|
|
427
|
+
q.breakable
|
428
|
+
q.text member.to_s
|
429
|
+
q.text '='
|
430
|
+
q.group(1) {
|
431
|
+
q.breakable ''
|
432
|
+
q.pp public_send(member)
|
433
|
+
}
|
434
|
+
}
|
435
|
+
}
|
436
|
+
end
|
437
|
+
|
438
|
+
def pretty_print_cycle(q) # :nodoc:
|
439
|
+
q.text sprintf("#<data %s:...>", PP.mcall(self, Kernel, :class).name)
|
440
|
+
end
|
441
|
+
end if "3.2" <= RUBY_VERSION
|
442
|
+
|
408
443
|
class Range # :nodoc:
|
409
444
|
def pretty_print(q) # :nodoc:
|
410
445
|
q.pp self.begin
|
@@ -598,10 +633,6 @@ end
|
|
598
633
|
module Kernel
|
599
634
|
# Returns a pretty printed object as a string.
|
600
635
|
#
|
601
|
-
# In order to use this method you must first require the PP module:
|
602
|
-
#
|
603
|
-
# require 'pp'
|
604
|
-
#
|
605
636
|
# See the PP module for more information.
|
606
637
|
def pretty_inspect
|
607
638
|
PP.pp(self, ''.dup)
|
data/pp.gemspec
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
name = File.basename(__FILE__, ".gemspec")
|
2
|
+
version = ["lib", Array.new(name.count("-")+1).join("/")].find do |dir|
|
3
|
+
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
|
4
|
+
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
|
5
|
+
end rescue nil
|
6
|
+
end
|
7
|
+
|
1
8
|
Gem::Specification.new do |spec|
|
2
|
-
spec.name =
|
3
|
-
spec.version =
|
9
|
+
spec.name = name
|
10
|
+
spec.version = version
|
4
11
|
spec.authors = ["Tanaka Akira"]
|
5
12
|
spec.email = ["akr@fsij.org"]
|
6
13
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tanaka Akira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prettyprint
|
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
requirements: []
|
59
|
-
rubygems_version: 3.
|
59
|
+
rubygems_version: 3.5.0.dev
|
60
60
|
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: Provides a PrettyPrinter for Ruby objects
|