ark-util 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ark/utility.rb +37 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8933c9374b25a7da33cb418a60e223c5a635236
|
4
|
+
data.tar.gz: d3cacf8addcb2e9ff29fe08b88167f106f13f602
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1f5f4e7903c52e6fdd087ce4a75fa461b0cd5bf2a55b155e80c25c4389eccbcfdb40b1433438686d4ba5cffcfeb80e5b25c20cd6e388d62ddc7a828e2912c3f
|
7
|
+
data.tar.gz: 186c8fb12845ef661c68b2ec67b52fa243baa647d56a73114d260c021fdc171101741fab8fd2815734101efbcec40984daeef72b7ee8cff7bcb41d7cae285d9e
|
data/lib/ark/utility.rb
CHANGED
@@ -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
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
132
|
-
|
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.
|
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-
|
11
|
+
date: 2015-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Utility library for ark-* gems
|
14
14
|
email:
|