indented_io 0.10.0 → 0.11.0
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.
- checksums.yaml +4 -4
- data/lib/indented_io/indented_io.rb +3 -3
- data/lib/indented_io/indented_io_interface.rb +14 -9
- data/lib/indented_io/io.rb +1 -1
- data/lib/indented_io/kernel.rb +1 -1
- data/lib/indented_io/stringio.rb +2 -2
- data/lib/indented_io/tempfile.rb +1 -1
- data/lib/indented_io/version.rb +1 -1
- data/lib/indented_io.rb +9 -9
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1ca4010d40987e7fcf41ef261e382d9c4dbd46aedf28b14b1b492e2d89514e69
|
|
4
|
+
data.tar.gz: 9ecb56b410ed532c145b438f1f08ab380ebd6f4003f38c9c851cfeba27c9f4f1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f3b9df5ccba732b79eefac135faa6a79a580e50bd954e7a1cea46d6a8f97adb2a116c4d63eb38f33cce17d096b35a008ac3b0e5c9f7bdc674615ea4b7951017
|
|
7
|
+
data.tar.gz: 5f54172ed68dfa74eea22303f283dce696d40db0f33fb21719e38c06d93db70626596571ff89822fed4e0ac59351d06bfb1a748a5434a94ae5104a238a0c747e
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'indented_io_interface'
|
|
2
2
|
|
|
3
3
|
module IndentedIO
|
|
4
4
|
# An IO device that writes indented text by reimplementing #write, #print,
|
|
@@ -6,7 +6,7 @@ module IndentedIO
|
|
|
6
6
|
#
|
|
7
7
|
# IndentedIO objects forms a chain that acts as a stack. The lowest element
|
|
8
8
|
# in the stack is always a "pure" IO object (eg. $stdout). IndentedIO object
|
|
9
|
-
# are
|
|
9
|
+
# are then moved on and off the stack as indentation levels rise or fall
|
|
10
10
|
#
|
|
11
11
|
# Note that #new is private. The only way to create a IndentedIO object is to
|
|
12
12
|
# call #indent on an object that supports it ({Kernel}, {IO}, or {StringIO})
|
|
@@ -137,7 +137,7 @@ module IndentedIO
|
|
|
137
137
|
def initialize(parent, levels, this_indent, bol)
|
|
138
138
|
if levels < 0
|
|
139
139
|
parent.is_a?(::IndentedIO::IndentedIO) or raise ::IndentedIO::Error.new "Negative levels argument"
|
|
140
|
-
parent.levels + levels >= 0 or raise ::IndentedIO::Error.new "
|
|
140
|
+
parent.levels + levels >= 0 or raise ::IndentedIO::Error.new "Levels out of range"
|
|
141
141
|
sibling = parent
|
|
142
142
|
while parent.is_a?(::IndentedIO::IndentedIO) && levels < 0
|
|
143
143
|
levels += parent.levels
|
|
@@ -20,19 +20,24 @@ module IndentedIO
|
|
|
20
20
|
module IndentedIOInterface
|
|
21
21
|
# Returns a IndentedIO object that can be used for printing. The IO object
|
|
22
22
|
# will pass-through all methods to the underlying device except #print,
|
|
23
|
-
# #printf, #puts, and #p
|
|
23
|
+
# #printf, #puts, and #p that extends the default to output indented text
|
|
24
24
|
#
|
|
25
|
-
# +level+ is the number of levels to indent
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
# {::IndentedIO.default_indent} if this is the first level. +:bol+ control the
|
|
29
|
-
# beginning-of-line status: If true, #indent will begin writing with an
|
|
30
|
-
# indentation string as if it was at the beginning of the line. If false,
|
|
31
|
-
# it will only indent after the first newline. Default is true
|
|
25
|
+
# +level+ is the number of levels to indent the following text. If +level+
|
|
26
|
+
# is negative, #indent will outdent text instead. +level' can also be true
|
|
27
|
+
# or false: true sets the level to 1 and false sets it to 0
|
|
32
28
|
#
|
|
33
|
-
#
|
|
29
|
+
# +string+ is the string used for indentation. The indentation string can
|
|
30
|
+
# also be given as the keyword parameter +:string+. Default is the indent
|
|
31
|
+
# string of the outer level or {::IndentedIO.default_indent} if this is the
|
|
32
|
+
# first level
|
|
33
|
+
#
|
|
34
|
+
# +:bol+ controls the beginning-of-line status: If true, #indent will begin
|
|
35
|
+
# writing with an indentation string as if it was at the beginning of the
|
|
36
|
+
# line. If false, it will only indent after the first newline. Default is
|
|
37
|
+
# true
|
|
34
38
|
#
|
|
35
39
|
def indent(levels = 1, string_ = ::IndentedIO.default_indent, string: string_, bol: nil, &block)
|
|
40
|
+
levels = levels.is_a?(Integer) ? levels : (levels && 1 || 0)
|
|
36
41
|
block.nil? || block.arity == 1 or raise ::IndentedIO::Error.new "Wrong number of block parameters"
|
|
37
42
|
@indented_io_object = ::IndentedIO::IndentedIO.send(:new, self, levels, string, bol)
|
|
38
43
|
block_given? ? yield(@indented_io_object) : @indented_io_object
|
data/lib/indented_io/io.rb
CHANGED
data/lib/indented_io/kernel.rb
CHANGED
data/lib/indented_io/stringio.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
require_relative 'stringio' # Required to avoid 'superclass mismatch' errors in other modules
|
|
2
|
+
require_relative 'indented_io_interface'
|
|
3
3
|
|
|
4
4
|
# Includes the IndentedIOInterface that define the #indent method
|
|
5
5
|
class StringIO
|
data/lib/indented_io/tempfile.rb
CHANGED
data/lib/indented_io/version.rb
CHANGED
data/lib/indented_io.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
require_relative 'indented_io/version'
|
|
3
|
+
require_relative 'indented_io/error'
|
|
4
|
+
require_relative 'indented_io/indented_io'
|
|
5
|
+
require_relative 'indented_io/indented_io_interface'
|
|
6
|
+
require_relative 'indented_io/kernel'
|
|
7
|
+
require_relative 'indented_io/io'
|
|
8
|
+
require_relative 'indented_io/stringio'
|
|
9
|
+
require_relative 'indented_io/tempfile'
|
|
10
10
|
|
|
11
|
-
# IndentedIO module. See {IndentedIO::IndentedIO} for documentation on how to
|
|
11
|
+
# IndentedIO module. See {IndentedIO::IndentedIO} for documentation on how to
|
|
12
12
|
# use this module
|
|
13
13
|
#
|
|
14
14
|
module IndentedIO
|