strings 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d3712358619d5f8d24a776c05e69e721a95bde5
4
- data.tar.gz: 06a4637fe88656f23a5e2d72f88184c6ed2a77fe
3
+ metadata.gz: 8c727435e43509b7a7e0cc9689156e11d0ce8e8b
4
+ data.tar.gz: 6c8b48a149487fa5f5531e2a758813b701450fe9
5
5
  SHA512:
6
- metadata.gz: e486b066d003f2f7445cea67b571b48c6705d34b07a684d489eb179d1fed143c6b9ed2fce4cfab5698e036947e9984c0ef3a47b00c1906141db18e2de8f8819d
7
- data.tar.gz: f4f9057f7003aaf5837f40d1d27de423e8288f94f4016c5590af01d0d09e39fd05d431f3090566e0baae0f5b5cb8f5bc195212d1f32e0aa51a95ff8d0b234ba1
6
+ metadata.gz: c7bc069057ee21ce39c90f6399182679bf5f6a822f84f51a210e5d1e85d94a4090632b9ffa3567a9abec3fd7cb8fceee03118be7cd711bb272652b4f99814fd6
7
+ data.tar.gz: c6219fcfc87b32052a8be2228ede6f7e40cb4a0634ab18e6cc157eff5783d88a76757f4092560d3dda82fa3b4ee731e494f630ce7417b8f9ba722f90df296aeb
@@ -10,6 +10,7 @@ rvm:
10
10
  - 2.2.8
11
11
  - 2.3.6
12
12
  - 2.4.3
13
+ - 2.5.0
13
14
  - ruby-head
14
15
  - jruby-9000
15
16
  - jruby-head
@@ -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 = "for there is no folly of the beast\nof the earth which\nis not infinitely\noutdone by the madness of men"
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
- String.align(text, 40, direction: :center)
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 like so:
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
- class String
339
- def wrap(*args)
340
- Strings.wrap(self, *args)
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 all strings in your system:
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.
@@ -19,3 +19,5 @@ environment:
19
19
  - ruby_version: "23-x64"
20
20
  - ruby_version: "24"
21
21
  - ruby_version: "24-x64"
22
+ - ruby_version: "25"
23
+ - ruby_version: "25-x64"
@@ -94,8 +94,8 @@ module Strings
94
94
  # @see Strings::Truncate#truncate
95
95
  #
96
96
  # @api public
97
- def truncate(text, truncate_at, options = {})
98
- Truncate.truncate(text, truncate_at, options)
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(text, wrap_at)
108
- Wrap.wrap(text, wrap_at)
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
@@ -1,3 +1,3 @@
1
1
  module Strings
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
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.0
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-01-07 00:00:00.000000000 Z
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