ark-util 0.2.4 → 0.3.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ark/utility.rb +37 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fa97d8986f4485c90256d45558ce37493efcddf
4
- data.tar.gz: fddb3c760b8a073842b41057c0f7fbbe9159b26e
3
+ metadata.gz: c8933c9374b25a7da33cb418a60e223c5a635236
4
+ data.tar.gz: d3cacf8addcb2e9ff29fe08b88167f106f13f602
5
5
  SHA512:
6
- metadata.gz: 561ec48a301ce15e6ccd9f02e27b22143b8e59eb34b6920a2951847846deab947511c8c348cb154f9e667c7f30dcd7c5404aae5e44c6d5e4e786a787c13476e9
7
- data.tar.gz: 8bcce1c7c3494f02d81c0c54d0751590e3da52e1597258b116aaea38a81a4fc31d84010556a3c1b02f593f0ca860d0fbfa5556d728b94ebe60e383889f59902b
6
+ metadata.gz: c1f5f4e7903c52e6fdd087ce4a75fa461b0cd5bf2a55b155e80c25c4389eccbcfdb40b1433438686d4ba5cffcfeb80e5b25c20cd6e388d62ddc7a828e2912c3f
7
+ data.tar.gz: 186c8fb12845ef661c68b2ec67b52fa243baa647d56a73114d260c021fdc171101741fab8fd2815734101efbcec40984daeef72b7ee8cff7bcb41d7cae285d9e
@@ -90,15 +90,42 @@ module Ark
90
90
 
91
91
  # Methods for manipulating text
92
92
  module Text
93
+
94
+ def self.wrap_segments(segments, width: 78, indent: 0, indent_after: false)
95
+ segments = segments.flatten.map(&:to_s)
96
+ lines = []
97
+ line = ''
98
+ current_indent = indent
99
+ segments.each do |seg|
100
+ if lines.empty? && indent_after
101
+ current_indent = 0
102
+ else
103
+ current_indent = indent
104
+ end
105
+ if line.size + seg.size >= width
106
+ lines << line
107
+ line = (' ' * indent) + seg
108
+ elsif line.empty?
109
+ line = (' ' * current_indent) + seg
110
+ else
111
+ line << ' ' << seg
112
+ end
113
+ end
114
+ lines << line if line
115
+ return lines.join("\n")
116
+ end
117
+
93
118
  # Wrap a string to a given width, with an optional indent. Indented text
94
119
  # will fall within the specified width.
95
120
  # [+text+] The text to be wrapped
96
121
  # [+width+] The number of columns to wrap within
97
122
  # [+indent+] Indent each wrapped line of +text+ by this number of columns
98
- def self.wrap(text, width: 78, indent: 0)
99
- width -= indent
100
- text = text.gsub(/\s+/, " ").gsub(/(.{1,#{width}})( |\Z)/, "\\1\n")
101
- text.gsub(/^/, ' ' * indent)
123
+ def self.wrap(text, width: 78, indent: 0, indent_after: false)
124
+ if text.is_a?(Array)
125
+ text = text.flatten.join(' ')
126
+ end
127
+ text = text.split(' ')
128
+ self.wrap_segments(text, width: width, indent: indent, indent_after: indent_after)
102
129
  end
103
130
  end
104
131
 
@@ -127,9 +154,12 @@ module Ark
127
154
 
128
155
  # Wrap the current line to +width+, with an optional +indent+. After
129
156
  # wrapping, the current line will be the last line wrapped.
130
- def wrap(width: 78, indent: 0)
131
- text = @lines[@line].join(' ')
132
- text = Text.wrap(text, width: width, indent: indent)
157
+ def wrap(width: 78, indent: 0, indent_after: false, segments: false)
158
+ if segments
159
+ text = Text.wrap_segments(@lines[@line], width: width, indent: indent, indent_after: indent_after)
160
+ else
161
+ text = Text.wrap(@lines[@line], width: width, indent: indent, indent_after: indent_after)
162
+ end
133
163
  @lines.delete_at(@line)
134
164
  @line -= 1
135
165
  text.split("\n").each {|line| self.next(line) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ark-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Macquarie Sharpless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-06 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Utility library for ark-* gems
14
14
  email: