strings 0.1.0 → 0.1.1
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/.travis.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/README.md +37 -18
- data/appveyor.yml +2 -0
- data/lib/strings.rb +4 -4
- data/lib/strings/extensions.rb +45 -0
- data/lib/strings/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c727435e43509b7a7e0cc9689156e11d0ce8e8b
|
4
|
+
data.tar.gz: 6c8b48a149487fa5f5531e2a758813b701450fe9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7bc069057ee21ce39c90f6399182679bf5f6a822f84f51a210e5d1e85d94a4090632b9ffa3567a9abec3fd7cb8fceee03118be7cd711bb272652b4f99814fd6
|
7
|
+
data.tar.gz: c6219fcfc87b32052a8be2228ede6f7e40cb4a0634ab18e6cc157eff5783d88a76757f4092560d3dda82fa3b4ee731e494f630ce7417b8f9ba722f90df296aeb
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.1.1] - 2018-02-20
|
4
|
+
|
5
|
+
### Added
|
6
|
+
* Add ability to refine String class with extensions
|
7
|
+
|
3
8
|
## [v0.1.0] - 2018-01-07
|
4
9
|
|
5
10
|
* Inital implementation and release
|
6
11
|
|
12
|
+
[v0.1.1]: https://github.com/piotrmurach/verse/compare/v0.1.0...v0.1.1
|
7
13
|
[v0.1.0]: https://github.com/piotrmurach/verse/compare/v0.1.0
|
data/README.md
CHANGED
@@ -84,20 +84,25 @@ Strings::Wrap.wrap(text, 30)
|
|
84
84
|
|
85
85
|
To align a given multiline text within a given `width` use `align`, `align_left`, `align_center` or `align_right`.
|
86
86
|
|
87
|
-
Given the following text:
|
87
|
+
Given the following multiline text:
|
88
88
|
|
89
89
|
```ruby
|
90
|
-
text =
|
90
|
+
text = <<-TEXT
|
91
|
+
for there is no folly of the beast
|
92
|
+
of the earth which
|
93
|
+
is not infinitely
|
94
|
+
outdone by the madness of men
|
95
|
+
TEXT
|
91
96
|
```
|
92
97
|
|
93
98
|
Passing `text` as first argument, the maximum width and `:direction` to align to:
|
94
99
|
|
95
100
|
```ruby
|
96
|
-
|
101
|
+
Strings.align(text, 40, direction: :center)
|
97
102
|
# =>
|
98
|
-
# " for there is no folly of the beast "
|
99
|
-
# " of the earth which "
|
100
|
-
# " is not infinitely "
|
103
|
+
# " for there is no folly of the beast \n"
|
104
|
+
# " of the earth which \n"
|
105
|
+
# " is not infinitely \n"
|
101
106
|
# " outdone by the madness of men "
|
102
107
|
```
|
103
108
|
|
@@ -106,9 +111,9 @@ You can also pass `:fill` option to replace default space character:
|
|
106
111
|
```ruby
|
107
112
|
Strings.align(text, 40, direction: :center, fill: '*')
|
108
113
|
# =>
|
109
|
-
# "***for there is no folly of the beast
|
110
|
-
# "***********of the earth which
|
111
|
-
# "***********is not infinitely
|
114
|
+
# "***for there is no folly of the beast***\n"
|
115
|
+
# "***********of the earth which***********\n"
|
116
|
+
# "***********is not infinitely************\n"
|
112
117
|
# "*****outdone by the madness of men******"
|
113
118
|
```
|
114
119
|
|
@@ -118,10 +123,10 @@ It handles `UTF-8` text:
|
|
118
123
|
text = "ラドクリフ\n、マラソン五輪\n代表に1万m出\n場にも含み"
|
119
124
|
Strings.align_left(text, 20)
|
120
125
|
# =>
|
121
|
-
# "ラドクリフ "
|
122
|
-
# "、マラソン五輪 "
|
123
|
-
# "代表に1万m出 "
|
124
|
-
# "場にも含み "
|
126
|
+
# "ラドクリフ \n"
|
127
|
+
# "、マラソン五輪 \n"
|
128
|
+
# "代表に1万m出 \n"
|
129
|
+
# "場にも含み \n"
|
125
130
|
```
|
126
131
|
|
127
132
|
### 2.2 ansi?
|
@@ -332,22 +337,36 @@ Strings::Wrap.wrap(text, wrap_at)
|
|
332
337
|
|
333
338
|
## 3. Extending String class
|
334
339
|
|
335
|
-
Though it is highly discouraged to polute core Ruby classes, you can add the required methods to `String` class
|
340
|
+
Though it is highly discouraged to polute core Ruby classes, you can add the required methods to `String` class by using refinements.
|
341
|
+
|
342
|
+
For example, if you wish to only extend strings with `wrap` method do:
|
336
343
|
|
337
344
|
```ruby
|
338
|
-
|
339
|
-
|
340
|
-
|
345
|
+
module MyStringExt
|
346
|
+
refine String do
|
347
|
+
def wrap(*args)
|
348
|
+
Strings.wrap(self, *args)
|
349
|
+
end
|
341
350
|
end
|
342
351
|
end
|
343
352
|
```
|
344
353
|
|
345
|
-
then `wrap` method will be available for
|
354
|
+
then `wrap` method will be available for any strings where refinement is applied:
|
346
355
|
|
347
356
|
```ruby
|
357
|
+
using MyStringExt
|
358
|
+
|
348
359
|
string.wrap(30)
|
349
360
|
```
|
350
361
|
|
362
|
+
However, if you want to include all the **Strings** methods:
|
363
|
+
|
364
|
+
```ruby
|
365
|
+
require 'strings/extensions'
|
366
|
+
|
367
|
+
using Strings::Extensions
|
368
|
+
```
|
369
|
+
|
351
370
|
## Development
|
352
371
|
|
353
372
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/appveyor.yml
CHANGED
data/lib/strings.rb
CHANGED
@@ -94,8 +94,8 @@ module Strings
|
|
94
94
|
# @see Strings::Truncate#truncate
|
95
95
|
#
|
96
96
|
# @api public
|
97
|
-
def truncate(
|
98
|
-
Truncate.truncate(
|
97
|
+
def truncate(*args)
|
98
|
+
Truncate.truncate(*args)
|
99
99
|
end
|
100
100
|
module_function :truncate
|
101
101
|
|
@@ -104,8 +104,8 @@ module Strings
|
|
104
104
|
# @see Strings::Wrap#wrap
|
105
105
|
#
|
106
106
|
# @api public
|
107
|
-
def wrap(
|
108
|
-
Wrap.wrap(
|
107
|
+
def wrap(*args)
|
108
|
+
Wrap.wrap(*args)
|
109
109
|
end
|
110
110
|
module_function :wrap
|
111
111
|
end # Strings
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../strings'
|
4
|
+
|
5
|
+
module Strings
|
6
|
+
module Extensions
|
7
|
+
refine String do
|
8
|
+
def align(*args)
|
9
|
+
Align.align(self, *args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def align_left(*args)
|
13
|
+
Align.align_left(self, *args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def align_right(*args)
|
17
|
+
Align.align_right(self, *args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def ansi?
|
21
|
+
ANSI.ansi?(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def fold(*args)
|
25
|
+
Fold.fold(self, *args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def pad(*args)
|
29
|
+
Pad.pad(self, *args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def sanitize
|
33
|
+
ANSI.sanitize(self)
|
34
|
+
end
|
35
|
+
|
36
|
+
def truncate(*args)
|
37
|
+
Truncate.truncate(self, *args)
|
38
|
+
end
|
39
|
+
|
40
|
+
def wrap(*args)
|
41
|
+
Wrap.wrap(self, *args)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end # Extensions
|
45
|
+
end # Strings
|
data/lib/strings/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode_utils
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/strings.rb
|
106
106
|
- lib/strings/align.rb
|
107
107
|
- lib/strings/ansi.rb
|
108
|
+
- lib/strings/extensions.rb
|
108
109
|
- lib/strings/fold.rb
|
109
110
|
- lib/strings/pad.rb
|
110
111
|
- lib/strings/padder.rb
|