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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7d7b56c7e800172496c55f99f9dc03636488bf6c4129443a68529863dc6a172
4
- data.tar.gz: 10d967b887989eced95e9fc7f3799d59219e4a76ca926556badf8ebb7e1c49b6
3
+ metadata.gz: 1ca4010d40987e7fcf41ef261e382d9c4dbd46aedf28b14b1b492e2d89514e69
4
+ data.tar.gz: 9ecb56b410ed532c145b438f1f08ab380ebd6f4003f38c9c851cfeba27c9f4f1
5
5
  SHA512:
6
- metadata.gz: 0cb712cf0d9926b09d385db2a37a3d0cb6e136a36f5cbd164dccf49954b93098a4b23b0f4c60548a79267697bbdeb9adf19efd07123762f79ca43ea77860797a
7
- data.tar.gz: a0986342ecbc58afb912146b30aefbaed2c186df34b4df5dfe8a838cdc631db51eba5524797e101471c1cfd8c5388f42a4a482bc7bbab4fd85cc0bbb765405a5
6
+ metadata.gz: 1f3b9df5ccba732b79eefac135faa6a79a580e50bd954e7a1cea46d6a8f97adb2a116c4d63eb38f33cce17d096b35a008ac3b0e5c9f7bdc674615ea4b7951017
7
+ data.tar.gz: 5f54172ed68dfa74eea22303f283dce696d40db0f33fb21719e38c06d93db70626596571ff89822fed4e0ac59351d06bfb1a748a5434a94ae5104a238a0c747e
@@ -1,4 +1,4 @@
1
- require 'indented_io/indented_io_interface'
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 than moved on and off the stack as indentation levels rise or fall
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 "levels out of range"
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 and +string+ is the string used
26
- # for indentation. The indentation string can also be given as the keyword
27
- # parameter +:string+. Default is the indent string of the outer level or
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
- # If +level+ is negative, #indent will outdent text instead
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
@@ -1,4 +1,4 @@
1
- require 'indented_io/indented_io_interface'
1
+ require_relative 'indented_io_interface'
2
2
 
3
3
  # Includes the IndentedIOInterface that define the #indent method
4
4
  class IO
@@ -1,4 +1,4 @@
1
- require 'indented_io/indented_io_interface'
1
+ require_relative 'indented_io_interface'
2
2
 
3
3
  module Kernel
4
4
  @@INDENT_STACK = []
@@ -1,5 +1,5 @@
1
- require 'stringio' # Requiered to avoid 'superclass mismatch' errors in other modules
2
- require 'indented_io/indented_io_interface'
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
@@ -1,4 +1,4 @@
1
- require 'indented_io/indented_io_interface'
1
+ require_relative 'indented_io_interface'
2
2
 
3
3
  require "tempfile"
4
4
 
@@ -1,4 +1,4 @@
1
1
  module IndentedIO
2
2
  # Version number
3
- VERSION = '0.10.0'
3
+ VERSION = '0.11.0'
4
4
  end
data/lib/indented_io.rb CHANGED
@@ -1,14 +1,14 @@
1
1
 
2
- require 'indented_io/version'
3
- require 'indented_io/error'
4
- require 'indented_io/indented_io'
5
- require 'indented_io/indented_io_interface'
6
- require 'indented_io/kernel'
7
- require 'indented_io/io'
8
- require 'indented_io/stringio'
9
- require 'indented_io/tempfile'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indented_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen