word_wrap 0.2.2 → 1.0.0

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: 97e65a495b6f2ab99437d44d8565e98d79eddd7f
4
- data.tar.gz: 04a1ea0995806340c097402e05849f88213fd286
3
+ metadata.gz: f32958e3d2e01f4e1deabf7599626fde63c7a077
4
+ data.tar.gz: 8af67835095f2840d0090f310782b4b5962ba8ba
5
5
  SHA512:
6
- metadata.gz: 64b90daf593b8bb1beb61d1507afd601c7eb5e32d90b15a88a3f2a9ee56830ff8dc59629991c8e88f2e93d182163b7b876c528c4beb79ec2589ba19e7082b318
7
- data.tar.gz: 3ae6e1ca2d5751e3725e30d85510f6a1f14813b88190108d5e3dad5eb5948db3c55ed130fdad6492f8b494137706902414e89ce6512df7a6cd5b10afeb116f25
6
+ metadata.gz: b2a1f7776dd333eeefd49b82305b846fa3ccb06ef33b6de3399170f07b6c85c93076f0f8ab0c6ba0cfa170639885e1f7eba70e0f246843b8686418e3a2da9a6a
7
+ data.tar.gz: 1fb5393d263491265fa25b16eb908b1306b2c6b0476ee53cef085a0def381ef5023f935e66018038b5abbb385cfdd48a71781f38ec0bda5c363a3193f74c0fed
@@ -12,21 +12,3 @@ module WordWrap
12
12
  fit ? w.fit : w.wrap
13
13
  end
14
14
  end
15
-
16
- class String
17
- def wrap(width=WordWrap::DEFAULT_WIDTH)
18
- WordWrap.ww(self, width, false)
19
- end
20
-
21
- def wrap!(width=WordWrap::DEFAULT_WIDTH)
22
- replace wrap(width)
23
- end
24
-
25
- def fit(width=WordWrap::DEFAULT_WIDTH)
26
- WordWrap.ww(self, width, true)
27
- end
28
-
29
- def fit!(width=WordWrap::DEFAULT_WIDTH)
30
- replace fit(width)
31
- end
32
- end
@@ -0,0 +1,26 @@
1
+ #
2
+ # core_ext.rb
3
+ #
4
+ # Copyright (c) 2015 Radek Pazdera
5
+ # Distributed under the MIT License
6
+ #
7
+ # Optional core exensions, adding the fit and wrap methods to the String class
8
+ #
9
+
10
+ class String
11
+ def wrap(width=WordWrap::DEFAULT_WIDTH)
12
+ WordWrap.ww(self, width, false)
13
+ end
14
+
15
+ def wrap!(width=WordWrap::DEFAULT_WIDTH)
16
+ replace wrap(width)
17
+ end
18
+
19
+ def fit(width=WordWrap::DEFAULT_WIDTH)
20
+ WordWrap.ww(self, width, true)
21
+ end
22
+
23
+ def fit!(width=WordWrap::DEFAULT_WIDTH)
24
+ replace fit(width)
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module WordWrap
2
- VERSION = "0.2.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,10 +1,12 @@
1
- # Copyright (c) 2014 Radek Pazdera
1
+ #
2
+ # wrapper.rb
3
+ #
4
+ # Copyright (c) 2014, 2015 Radek Pazdera
2
5
  # Distributed under the MIT License
3
-
4
- # The actual implementation of wrapping
5
- # TODO: share code between wrap and fit implementations
6
+ #
6
7
 
7
8
  module WordWrap
9
+ # TODO: Refactor similar passages out of the two functions into a common one
8
10
  class Wrapper
9
11
  def initialize(text, width)
10
12
  @text = text
@@ -14,7 +16,6 @@ module WordWrap
14
16
  def fit
15
17
  lines = []
16
18
  next_line = ""
17
- continued = false
18
19
  @text.lines do |line|
19
20
  line.chomp! "\n"
20
21
  if line.length == 0
@@ -0,0 +1,49 @@
1
+ # Copyright (c) 2015 Radek Pazdera
2
+ # Distributed under the MIT License
3
+
4
+ # Tests for the extensions of the String class
5
+
6
+ require 'word_wrap/core_ext'
7
+
8
+ describe WordWrap do
9
+ describe "core extensions" do
10
+ it "fit as a part of String interface" do
11
+ text =<<EOF
12
+ Try-hard 3 wolf moon vinyl.
13
+
14
+ Mumblecore letterpress iPhone.
15
+ EOF
16
+
17
+ expected =<<EOF
18
+ Try-hard 3 wolf moon
19
+ vinyl.
20
+
21
+ Mumblecore
22
+ letterpress iPhone.
23
+ EOF
24
+ expect(text.fit(20)).to eql expected
25
+ end
26
+
27
+ it "wraps in-place" do
28
+ text = "0123456789 01234 0123456"
29
+ expected =<<EOF
30
+ 0123456789
31
+ 01234
32
+ 0123456
33
+ EOF
34
+ text.wrap! 10
35
+ expect(text).to eql expected
36
+ end
37
+
38
+ it "fits in-place" do
39
+ text = "0123456789 01234 0123456"
40
+ expected =<<EOF
41
+ 0123456789
42
+ 01234
43
+ 0123456
44
+ EOF
45
+ text.fit! 10
46
+ expect(text).to eql expected
47
+ end
48
+ end
49
+ end
@@ -1,9 +1,9 @@
1
- # Copyright (c) 2014 Radek Pazdera
1
+ # Copyright (c) 2014, 2015 Radek Pazdera
2
2
  # Distributed under the MIT License
3
3
 
4
- # Several tests for the ww function
4
+ # Tests for the ww function
5
5
 
6
- require "word_wrap"
6
+ require 'word_wrap'
7
7
 
8
8
  describe WordWrap do
9
9
  describe "#ww" do
@@ -15,7 +15,7 @@ describe WordWrap do
15
15
  0123456
16
16
  EOF
17
17
  wrapped = WordWrap.ww(text, 10)
18
- wrapped.should eql expected
18
+ expect(wrapped).to eql expected
19
19
  end
20
20
 
21
21
  it "works without breaks" do
@@ -31,7 +31,7 @@ EOF
31
31
  0123456
32
32
  EOF
33
33
  wrapped = WordWrap.ww(text, 10)
34
- wrapped.should eql expected
34
+ expect(wrapped).to eql expected
35
35
  end
36
36
 
37
37
  it "wraps two paragraphs" do
@@ -59,7 +59,7 @@ distillery cray
59
59
  semiotics.
60
60
  EOF
61
61
  wrapped = WordWrap.ww(text, 20)
62
- wrapped.should eql expected
62
+ expect(wrapped).to eql expected
63
63
  end
64
64
 
65
65
  it "wraps a partialy wrapped paragraph" do
@@ -84,7 +84,7 @@ out pop-up direct
84
84
  trade.
85
85
  EOF
86
86
  wrapped = WordWrap.ww(text, 20)
87
- wrapped.should eql expected
87
+ expect(wrapped).to eql expected
88
88
  end
89
89
 
90
90
  it "wrapping keeps whitespace" do
@@ -121,7 +121,7 @@ extremelylonganduglyword
121
121
 
122
122
  EOF
123
123
  wrapped = WordWrap.ww(text, 20)
124
- wrapped.should eql expected
124
+ expect(wrapped).to eql expected
125
125
  end
126
126
 
127
127
  it "wrap as a part of String interface" do
@@ -138,7 +138,7 @@ moon vinyl.
138
138
  Mumblecore
139
139
  letterpress iPhone.
140
140
  EOF
141
- text.wrap(20).should eql expected
141
+ expect(text.wrap(20)).to eql expected
142
142
  end
143
143
 
144
144
  it "fits a single line correctly" do
@@ -149,7 +149,7 @@ EOF
149
149
  0123456
150
150
  EOF
151
151
  wrapped = WordWrap.ww(text, 10, true)
152
- wrapped.should eql expected
152
+ expect(wrapped).to eql expected
153
153
  end
154
154
 
155
155
  it "works without breaks" do
@@ -164,7 +164,7 @@ EOF
164
164
  0123456
165
165
  EOF
166
166
  wrapped = WordWrap.ww(text, 10, true)
167
- wrapped.should eql expected
167
+ expect(wrapped).to eql expected
168
168
  end
169
169
 
170
170
  it "fits two paragraphs" do
@@ -191,7 +191,7 @@ distillery cray
191
191
  semiotics.
192
192
  EOF
193
193
  wrapped = WordWrap.ww(text, 20, true)
194
- wrapped.should eql expected
194
+ expect(wrapped).to eql expected
195
195
  end
196
196
 
197
197
  it "fits a partialy wrapped paragraph" do
@@ -214,7 +214,7 @@ they sold out pop-up
214
214
  direct trade.
215
215
  EOF
216
216
  wrapped = WordWrap.ww(text, 20, true)
217
- wrapped.should eql expected
217
+ expect(wrapped).to eql expected
218
218
  end
219
219
 
220
220
  it "fitting keeps empty lines" do
@@ -249,46 +249,7 @@ extremelylonganduglyword
249
249
 
250
250
  EOF
251
251
  wrapped = WordWrap.ww(text, 20, true)
252
- wrapped.should eql expected
253
- end
254
-
255
- it "fit as a part of String interface" do
256
- text =<<EOF
257
- Try-hard 3 wolf moon vinyl.
258
-
259
- Mumblecore letterpress iPhone.
260
- EOF
261
-
262
- expected =<<EOF
263
- Try-hard 3 wolf moon
264
- vinyl.
265
-
266
- Mumblecore
267
- letterpress iPhone.
268
- EOF
269
- text.fit(20).should eql expected
270
- end
271
-
272
- it "wraps in-place" do
273
- text = "0123456789 01234 0123456"
274
- expected =<<EOF
275
- 0123456789
276
- 01234
277
- 0123456
278
- EOF
279
- text.wrap! 10
280
- text.should eql expected
281
- end
282
-
283
- it "fits in-place" do
284
- text = "0123456789 01234 0123456"
285
- expected =<<EOF
286
- 0123456789
287
- 01234
288
- 0123456
289
- EOF
290
- text.fit! 10
291
- text.should eql expected
252
+ expect(wrapped).to eql expected
292
253
  end
293
254
  end
294
255
  end
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.5"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rake", "~> 0"
25
+ spec.add_development_dependency "rspec", "~> 0"
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: word_wrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Radek Pazdera
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,28 +28,28 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: |-
@@ -70,8 +70,10 @@ files:
70
70
  - Rakefile
71
71
  - bin/ww
72
72
  - lib/word_wrap.rb
73
+ - lib/word_wrap/core_ext.rb
73
74
  - lib/word_wrap/version.rb
74
75
  - lib/word_wrap/wrapper.rb
76
+ - spec/core_ext_spec.rb
75
77
  - spec/ww_spec.rb
76
78
  - word_wrap.gemspec
77
79
  homepage: https://github.com/pazdera/word_wrap
@@ -99,5 +101,6 @@ signing_key:
99
101
  specification_version: 4
100
102
  summary: Simple tool for word-wrapping text
101
103
  test_files:
104
+ - spec/core_ext_spec.rb
102
105
  - spec/ww_spec.rb
103
106
  has_rdoc: