pp 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pp.rb +36 -5
  3. data/pp.gemspec +9 -2
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f66fc26d251e735dab9c7dcc24cbd90ec1616ac358535379358242dea131e5e
4
- data.tar.gz: a04b828096786c7d6de187bcacda6fdb7a3bf246b7dab7399347039feb9dedac
3
+ metadata.gz: 05c96009c03ef3d1fb5542a17f2833a93b128a7579380a4c608384fc6232d5a7
4
+ data.tar.gz: 629c3161e24420959ea1946d612f22ce4b73694f7e5c805499fb166f75cd9de8
5
5
  SHA512:
6
- metadata.gz: a2b9327741655b4fa03bf3cd2d32113022b4164fdd48608cafdd3abe5b80e394d0fb8b3ebe2acb7818c60d68103ba5cb0900ba9e20d988baac3e311bb8424ace
7
- data.tar.gz: 6bceee1000233e7083f9e3e87aeba7bf28a257acc48a453e88d928bffe0180f65af0c3e70a636dfc9e33e1307c51831a03182308f2f18d51f0d10d53a79bfc9c
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, 79 is assumed.
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 = "pp"
3
- spec.version = "0.3.0"
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.3.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: 2021-12-20 00:00:00.000000000 Z
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.3.0.dev
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