lovely_rufus 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -12
- data/Gemfile.lock +30 -32
- data/Rakefile +5 -3
- data/bin/lovely-rufus +1 -0
- data/config/reek.yml +9 -12
- data/lib/lovely_rufus/basic_wrapper.rb +11 -6
- data/lib/lovely_rufus/cli_wrapper.rb +14 -24
- data/lib/lovely_rufus/hangout_wrapper.rb +30 -24
- data/lib/lovely_rufus/layer.rb +12 -10
- data/lib/lovely_rufus/one_letter_gluer.rb +11 -6
- data/lib/lovely_rufus/quote_stripper.rb +26 -21
- data/lib/lovely_rufus/settings.rb +14 -0
- data/lib/lovely_rufus/text_wrapper.rb +31 -22
- data/lib/lovely_rufus/wrap.rb +3 -6
- data/lib/lovely_rufus.rb +7 -9
- data/lovely_rufus.gemspec +8 -7
- data/spec/lovely_rufus/basic_wrapper_spec.rb +43 -39
- data/spec/lovely_rufus/cli_wrapper_spec.rb +24 -20
- data/spec/lovely_rufus/hangout_wrapper_spec.rb +24 -19
- data/spec/lovely_rufus/one_letter_gluer_spec.rb +25 -20
- data/spec/lovely_rufus/quote_stripper_spec.rb +109 -105
- data/spec/lovely_rufus/settings_spec.rb +20 -0
- data/spec/lovely_rufus/text_wrapper_spec.rb +42 -37
- data/spec/lovely_rufus/wrap_spec.rb +21 -18
- data/spec/lovely_rufus_spec.rb +51 -0
- data/spec/spec_helper.rb +0 -1
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49c92b0710902ad7b5974120c3259511bca506b9
|
4
|
+
data.tar.gz: bacdd2b6ed4093103944c30e464defca9c88fd67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23d1be28b58049eb916bb07390880e487e81c960ad3315212de2fe396e225f695ed9f2489c3254d55efac807f88d73521d791c800b9b4211754b8d5f29978f86
|
7
|
+
data.tar.gz: 4258e4a7562d74568f4c1fa2a26df4cddf9d2b93691f8582418e931ccd8904be057ba7721e5a6992fefb7f994cb897ea5091df89f655b3b60b82b965efa3cd49
|
data/.rubocop.yml
CHANGED
@@ -1,25 +1,13 @@
|
|
1
|
-
AccessModifierIndentation:
|
2
|
-
Enabled: false
|
3
|
-
|
4
1
|
AndOr:
|
5
2
|
Enabled: false
|
6
3
|
|
7
4
|
Documentation:
|
8
5
|
Enabled: false
|
9
6
|
|
10
|
-
EndAlignment:
|
11
|
-
Enabled: false
|
12
|
-
|
13
7
|
FileName:
|
14
8
|
Exclude:
|
15
9
|
- bin/lovely-rufus
|
16
10
|
|
17
|
-
IndentationWidth:
|
18
|
-
Enabled: false
|
19
|
-
|
20
|
-
MethodDefParentheses:
|
21
|
-
EnforcedStyle: require_no_parentheses
|
22
|
-
|
23
11
|
SingleLineBlockParams:
|
24
12
|
Enabled: false
|
25
13
|
|
data/Gemfile.lock
CHANGED
@@ -6,57 +6,55 @@ PATH
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
ast (
|
10
|
-
|
9
|
+
ast (2.0.0)
|
10
|
+
astrolabe (1.3.0)
|
11
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
12
|
+
bogus (0.1.5)
|
11
13
|
dependor (>= 0.0.4)
|
12
|
-
celluloid (0.
|
13
|
-
timers (~>
|
14
|
-
celluloid-io (0.15.0)
|
15
|
-
celluloid (>= 0.15.0)
|
16
|
-
nio4r (>= 0.5.0)
|
14
|
+
celluloid (0.16.0)
|
15
|
+
timers (~> 4.0.0)
|
17
16
|
dependor (1.0.1)
|
18
17
|
ffi (1.9.3)
|
19
|
-
|
20
|
-
listen (2.7.
|
18
|
+
hitimes (1.2.2)
|
19
|
+
listen (2.7.9)
|
21
20
|
celluloid (>= 0.15.2)
|
22
|
-
celluloid-io (>= 0.15.0)
|
23
21
|
rb-fsevent (>= 0.9.3)
|
24
22
|
rb-inotify (>= 0.9)
|
25
|
-
minitest (5.
|
23
|
+
minitest (5.4.1)
|
26
24
|
minitest-focus (1.1.0)
|
27
25
|
minitest (>= 4, < 6)
|
28
|
-
|
29
|
-
|
30
|
-
ast (~> 1.1)
|
26
|
+
parser (2.2.0.pre.4)
|
27
|
+
ast (>= 1.1, < 3.0)
|
31
28
|
slop (~> 3.4, >= 3.4.5)
|
32
29
|
powerpack (0.0.9)
|
33
30
|
rainbow (2.0.0)
|
34
|
-
rake (10.
|
31
|
+
rake (10.3.2)
|
35
32
|
rb-fsevent (0.9.4)
|
36
|
-
rb-inotify (0.9.
|
33
|
+
rb-inotify (0.9.5)
|
37
34
|
ffi (>= 0.5.0)
|
38
|
-
reek (1.3.
|
39
|
-
rainbow
|
40
|
-
ruby2ruby (
|
35
|
+
reek (1.3.8)
|
36
|
+
rainbow (>= 1.99, < 3.0)
|
37
|
+
ruby2ruby (>= 2.0.8, < 3.0)
|
41
38
|
ruby_parser (~> 3.3)
|
42
39
|
sexp_processor
|
43
|
-
rerun (0.
|
44
|
-
listen (~> 2.7)
|
45
|
-
rubocop (0.
|
46
|
-
|
47
|
-
parser (
|
40
|
+
rerun (0.10.0)
|
41
|
+
listen (~> 2.7, >= 2.7.3)
|
42
|
+
rubocop (0.26.0)
|
43
|
+
astrolabe (~> 1.3)
|
44
|
+
parser (>= 2.2.0.pre.4, < 3.0)
|
48
45
|
powerpack (~> 0.0.6)
|
49
46
|
rainbow (>= 1.99.1, < 3.0)
|
50
47
|
ruby-progressbar (~> 1.4)
|
51
|
-
ruby-progressbar (1.
|
52
|
-
ruby2ruby (2.
|
48
|
+
ruby-progressbar (1.5.1)
|
49
|
+
ruby2ruby (2.1.2)
|
53
50
|
ruby_parser (~> 3.1)
|
54
51
|
sexp_processor (~> 4.0)
|
55
|
-
ruby_parser (3.
|
52
|
+
ruby_parser (3.6.2)
|
56
53
|
sexp_processor (~> 4.1)
|
57
|
-
sexp_processor (4.4.
|
58
|
-
slop (3.
|
59
|
-
timers (
|
54
|
+
sexp_processor (4.4.4)
|
55
|
+
slop (3.6.0)
|
56
|
+
timers (4.0.1)
|
57
|
+
hitimes
|
60
58
|
|
61
59
|
PLATFORMS
|
62
60
|
ruby
|
@@ -68,5 +66,5 @@ DEPENDENCIES
|
|
68
66
|
minitest-focus (~> 1.1)
|
69
67
|
rake (~> 10.1)
|
70
68
|
reek (~> 1.3)
|
71
|
-
rerun (~> 0.
|
72
|
-
rubocop (~> 0.
|
69
|
+
rerun (~> 0.10.0)
|
70
|
+
rubocop (~> 0.26.0)
|
data/Rakefile
CHANGED
@@ -2,9 +2,9 @@ require 'rake/testtask'
|
|
2
2
|
require 'reek/rake/task'
|
3
3
|
require 'rubocop/rake_task'
|
4
4
|
|
5
|
-
task default: %i
|
5
|
+
task default: %i(spec rubocop reek)
|
6
6
|
|
7
|
-
Rake::TestTask.new
|
7
|
+
Rake::TestTask.new(:spec) do |task|
|
8
8
|
task.test_files = FileList['spec/**/*_spec.rb']
|
9
9
|
task.warning = true
|
10
10
|
end
|
@@ -15,4 +15,6 @@ Reek::Rake::Task.new do |task|
|
|
15
15
|
task.reek_opts = '--quiet'
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
RuboCop::RakeTask.new do |task|
|
19
|
+
task.options << '--display-cop-names'
|
20
|
+
end
|
data/bin/lovely-rufus
CHANGED
data/config/reek.yml
CHANGED
@@ -1,25 +1,22 @@
|
|
1
1
|
DuplicateMethodCall:
|
2
2
|
exclude:
|
3
|
-
|
4
|
-
|
3
|
+
- LovelyRufus::BasicWrapper#call
|
4
|
+
- LovelyRufus::HangoutWrapper#rewrapped
|
5
5
|
|
6
6
|
FeatureEnvy:
|
7
7
|
exclude:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
- LovelyRufus::BasicWrapper#call
|
9
|
+
- LovelyRufus::HangoutWrapper#hangout_line
|
10
|
+
- LovelyRufus::OneLetterGluer#call
|
11
|
+
- LovelyRufus::QuoteStripper#quote
|
12
12
|
|
13
13
|
IrresponsibleModule:
|
14
14
|
enabled: false
|
15
15
|
|
16
16
|
NestedIterators:
|
17
|
-
max_allowed_nesting: 2
|
18
|
-
|
19
|
-
UncommunicativeVariableName:
|
20
17
|
exclude:
|
21
|
-
|
18
|
+
- LovelyRufus#initialize
|
22
19
|
|
23
|
-
|
20
|
+
UncommunicativeVariableName:
|
24
21
|
exclude:
|
25
|
-
|
22
|
+
- LovelyRufus::HangoutWrapper#hangout_line
|
@@ -1,7 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require_relative 'layer'
|
2
|
+
require_relative 'wrap'
|
3
|
+
|
4
|
+
module LovelyRufus
|
5
|
+
class BasicWrapper < Layer
|
6
|
+
def call(wrap)
|
7
|
+
unwrapped = wrap.text.tr("\n", ' ').strip
|
8
|
+
wrapped = unwrapped.gsub(/(.{1,#{wrap.width}})( |$\n?)/, "\\1\n")
|
9
|
+
next_layer.call(Wrap[wrapped, width: wrap.width])
|
10
|
+
end
|
6
11
|
end
|
7
|
-
end
|
12
|
+
end
|
@@ -1,28 +1,18 @@
|
|
1
|
-
|
1
|
+
require_relative 'settings'
|
2
|
+
require_relative 'text_wrapper'
|
2
3
|
|
3
|
-
module LovelyRufus
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def run stream = $stdin
|
10
|
-
puts text_wrapper.wrap stream.read, width: settings.width
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :settings, :text_wrapper
|
14
|
-
private :settings, :text_wrapper
|
15
|
-
|
16
|
-
class Settings
|
17
|
-
attr_reader :width
|
4
|
+
module LovelyRufus
|
5
|
+
class CLIWrapper
|
6
|
+
def initialize(args = ARGV, text_wrapper: TextWrapper)
|
7
|
+
@settings = Settings.new(args)
|
8
|
+
@text_wrapper = text_wrapper
|
9
|
+
end
|
18
10
|
|
19
|
-
def
|
20
|
-
|
21
|
-
OptionParser.new do |opts|
|
22
|
-
opts.on '-w', '--width WIDTH', Integer, 'Wrapping width' do |width|
|
23
|
-
@width = width
|
24
|
-
end
|
25
|
-
end.parse! args
|
11
|
+
def run(stream = $stdin)
|
12
|
+
puts text_wrapper.wrap(stream.read, width: settings.width)
|
26
13
|
end
|
14
|
+
|
15
|
+
attr_reader :settings, :text_wrapper
|
16
|
+
private :settings, :text_wrapper
|
27
17
|
end
|
28
|
-
end
|
18
|
+
end
|
@@ -1,32 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
require_relative 'basic_wrapper'
|
2
|
+
require_relative 'layer'
|
3
|
+
require_relative 'wrap'
|
4
|
+
|
5
|
+
module LovelyRufus
|
6
|
+
class HangoutWrapper < Layer
|
7
|
+
def call(wrap)
|
8
|
+
@wrap = wrap
|
9
|
+
final = hangout_line ? rewrapped : wrap.text
|
10
|
+
next_layer.call(Wrap[final, width: wrap.width])
|
11
|
+
end
|
7
12
|
|
8
|
-
|
9
|
-
|
13
|
+
attr_reader :wrap
|
14
|
+
private :wrap
|
10
15
|
|
11
|
-
|
16
|
+
private
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
def hangout_line
|
19
|
+
lines.each_cons(2) do |a, b|
|
20
|
+
return a if a[/\p{space}/] and a.rindex(/\p{space}/) >= b.size
|
21
|
+
unless b == lines.last
|
22
|
+
return b if b[/\p{space}/] and b.rindex(/\p{space}/) >= a.size
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
20
|
-
end
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
def lines
|
28
|
+
@lines ||= wrap.text.lines.map(&:chomp)
|
29
|
+
end
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
def rewrapped
|
32
|
+
hangout_line << NBSP
|
33
|
+
unfolded = lines.join(' ').gsub("#{NBSP} ", NBSP)
|
34
|
+
wrapped = BasicWrapper.new.call(Wrap[unfolded, width: wrap.width]).text
|
35
|
+
HangoutWrapper.new.call(Wrap[wrapped, width: wrap.width]).text
|
36
|
+
end
|
31
37
|
end
|
32
|
-
end
|
38
|
+
end
|
data/lib/lovely_rufus/layer.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
module LovelyRufus
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module LovelyRufus
|
2
|
+
class Layer
|
3
|
+
def initialize(next_layer = -> (wrap) { wrap })
|
4
|
+
@next_layer = next_layer
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def call(_opts = {})
|
8
|
+
fail 'Layer subclasses must define #call'
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
11
|
+
attr_reader :next_layer
|
12
|
+
private :next_layer
|
13
|
+
end
|
14
|
+
end
|
@@ -1,7 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require_relative 'layer'
|
2
|
+
require_relative 'wrap'
|
3
|
+
|
4
|
+
module LovelyRufus
|
5
|
+
class OneLetterGluer < Layer
|
6
|
+
def call(wrap)
|
7
|
+
pattern = /(?<=\p{space})(&|\p{letter})\p{space}/
|
8
|
+
text = wrap.text.gsub(pattern, "\\1\\2#{NBSP}")
|
9
|
+
next_layer.call(Wrap[text, width: wrap.width])
|
10
|
+
end
|
6
11
|
end
|
7
|
-
end
|
12
|
+
end
|
@@ -1,27 +1,32 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
@wrap = wrap
|
4
|
-
wrapped = next_layer.call stripped_wrap
|
5
|
-
quoted = wrapped.text.lines.map { |line| fixed_quote + line }.join
|
6
|
-
Wrap[quoted, width: wrapped.width + fixed_quote.size]
|
7
|
-
end
|
1
|
+
require_relative 'layer'
|
2
|
+
require_relative 'wrap'
|
8
3
|
|
9
|
-
|
10
|
-
|
4
|
+
module LovelyRufus
|
5
|
+
class QuoteStripper < Layer
|
6
|
+
def call(wrap)
|
7
|
+
@wrap = wrap
|
8
|
+
wrapped = next_layer.call(stripped_wrap)
|
9
|
+
quoted = wrapped.text.lines.map { |line| fixed_quote + line }.join
|
10
|
+
Wrap[quoted, width: wrapped.width + fixed_quote.size]
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
+
attr_reader :wrap
|
14
|
+
private :wrap
|
13
15
|
|
14
|
-
|
15
|
-
quote.size > 0 ? quote.delete(' ') + ' ' : ''
|
16
|
-
end
|
16
|
+
private
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def fixed_quote
|
19
|
+
quote.size > 0 ? quote.delete(' ') + ' ' : ''
|
20
|
+
end
|
21
|
+
|
22
|
+
def quote
|
23
|
+
starts = wrap.text.lines.map { |line| line[QUOTES] }.uniq
|
24
|
+
starts.size == 1 ? starts.first || '' : ''
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
def stripped_wrap
|
28
|
+
stripped_text = wrap.text.lines.map { |line| line[quote.size..-1] }.join
|
29
|
+
Wrap[stripped_text, width: wrap.width - fixed_quote.size]
|
30
|
+
end
|
26
31
|
end
|
27
|
-
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module LovelyRufus
|
4
|
+
Settings = Struct.new(:width) do
|
5
|
+
def initialize(args)
|
6
|
+
self.width = 72
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.on('-w', '--width=WIDTH', Integer, 'Wrapping width') do |width|
|
9
|
+
self.width = width
|
10
|
+
end
|
11
|
+
end.parse! args
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,29 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require_relative 'basic_wrapper'
|
2
|
+
require_relative 'hangout_wrapper'
|
3
|
+
require_relative 'one_letter_gluer'
|
4
|
+
require_relative 'quote_stripper'
|
5
|
+
require_relative 'wrap'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
module LovelyRufus
|
8
|
+
class TextWrapper
|
9
|
+
def self.wrap(text, width: 72)
|
10
|
+
new(Wrap[text, width: width]).call
|
11
|
+
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end.join "\n"
|
14
|
-
end
|
13
|
+
def initialize(wrap)
|
14
|
+
@wrap = wrap
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
def call
|
18
|
+
paras.map do |para|
|
19
|
+
chain.call(Wrap[para, width: wrap.width]).text.tr(NBSP, ' ')
|
20
|
+
end.join("\n")
|
21
|
+
end
|
18
22
|
|
19
|
-
|
23
|
+
attr_reader :wrap
|
24
|
+
private :wrap
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
private
|
27
|
+
|
28
|
+
def chain
|
29
|
+
layers = [QuoteStripper, OneLetterGluer, BasicWrapper, HangoutWrapper]
|
30
|
+
identity = -> (wrap) { wrap }
|
31
|
+
layers.reverse.reduce(identity) { |inner, outer| outer.new(inner) }
|
32
|
+
end
|
25
33
|
|
26
|
-
|
27
|
-
|
34
|
+
def paras
|
35
|
+
wrap.text.split(/\n#{QUOTES}?\n/).reject { |par| par[/^(#{QUOTES}| )$/] }
|
36
|
+
end
|
28
37
|
end
|
29
|
-
end
|
38
|
+
end
|
data/lib/lovely_rufus/wrap.rb
CHANGED
data/lib/lovely_rufus.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
require_relative 'lovely_rufus/layer'
|
2
|
-
require_relative 'lovely_rufus/basic_wrapper'
|
3
|
-
require_relative 'lovely_rufus/cli_wrapper'
|
4
|
-
require_relative 'lovely_rufus/hangout_wrapper'
|
5
|
-
require_relative 'lovely_rufus/one_letter_gluer'
|
6
|
-
require_relative 'lovely_rufus/quote_stripper'
|
7
|
-
require_relative 'lovely_rufus/text_wrapper'
|
8
|
-
require_relative 'lovely_rufus/wrap'
|
9
|
-
|
10
1
|
module LovelyRufus
|
11
2
|
NBSP = "\u00A0"
|
12
3
|
QUOTES = /^([>\/#])(\1| )*/
|
4
|
+
|
5
|
+
def self.wrap(text, width: 72)
|
6
|
+
TextWrapper.wrap(text, width: width)
|
7
|
+
end
|
13
8
|
end
|
9
|
+
|
10
|
+
require_relative 'lovely_rufus/cli_wrapper'
|
11
|
+
require_relative 'lovely_rufus/text_wrapper'
|
data/lovely_rufus.gemspec
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.author = 'Piotr Szotkowski'
|
3
|
-
gem.description = 'An executable and a Ruby library for wrapping
|
3
|
+
gem.description = 'An executable and a Ruby library for wrapping ' \
|
4
|
+
'paragraphs of text.'
|
4
5
|
gem.email = 'chastell@chastell.net'
|
5
6
|
gem.homepage = 'http://github.com/chastell/lovely_rufus'
|
6
7
|
gem.license = 'AGPL-3.0'
|
7
8
|
gem.name = 'lovely_rufus'
|
8
9
|
gem.summary = 'lovely_rufus: text wrapper'
|
9
|
-
gem.version = '0.
|
10
|
+
gem.version = '0.2.0'
|
10
11
|
|
11
|
-
gem.files = `git ls-files -z`.split
|
12
|
-
gem.executables = gem.files.grep(
|
13
|
-
gem.test_files = gem.files.grep
|
12
|
+
gem.files = `git ls-files -z`.split("\0")
|
13
|
+
gem.executables = gem.files.grep(/^bin\//).map { |path| File.basename(path) }
|
14
|
+
gem.test_files = gem.files.grep(/^spec\/.*\.rb$/)
|
14
15
|
|
15
16
|
gem.add_development_dependency 'bogus', '~> 0.1.4'
|
16
17
|
gem.add_development_dependency 'minitest', '~> 5.0'
|
17
18
|
gem.add_development_dependency 'minitest-focus', '~> 1.1'
|
18
19
|
gem.add_development_dependency 'rake', '~> 10.1'
|
19
20
|
gem.add_development_dependency 'reek', '~> 1.3'
|
20
|
-
gem.add_development_dependency 'rerun', '~> 0.
|
21
|
-
gem.add_development_dependency 'rubocop', '~> 0.
|
21
|
+
gem.add_development_dependency 'rerun', '~> 0.10.0'
|
22
|
+
gem.add_development_dependency 'rubocop', '~> 0.26.0'
|
22
23
|
end
|
@@ -1,49 +1,53 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/lovely_rufus/basic_wrapper'
|
3
|
+
require_relative '../../lib/lovely_rufus/wrap'
|
2
4
|
|
3
|
-
module LovelyRufus
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
module LovelyRufus
|
6
|
+
describe BasicWrapper do
|
7
|
+
describe '#call' do
|
8
|
+
it 'wraps text to the given width' do
|
9
|
+
text = 'I go crazy when I hear a cymbal and a hi-hat ' \
|
10
|
+
'with a souped-up tempo'
|
11
|
+
wrap = <<-end.dedent
|
12
|
+
I go crazy when I hear
|
13
|
+
a cymbal and a hi-hat
|
14
|
+
with a souped-up tempo
|
15
|
+
end
|
16
|
+
bw = BasicWrapper.new
|
17
|
+
bw.call(Wrap[text, width: 22]).must_equal Wrap[wrap, width: 22]
|
12
18
|
end
|
13
|
-
bw = BasicWrapper.new
|
14
|
-
bw.call(Wrap[text, width: 22]).must_equal Wrap[wrap, width: 22]
|
15
|
-
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
it 'extends past the given width when necessary' do
|
21
|
+
text = 'I’m killing your brain like a poisonous mushroom'
|
22
|
+
wrap = <<-end.dedent
|
23
|
+
I’m
|
24
|
+
killing
|
25
|
+
your
|
26
|
+
brain
|
27
|
+
like
|
28
|
+
a
|
29
|
+
poisonous
|
30
|
+
mushroom
|
31
|
+
end
|
32
|
+
bw = BasicWrapper.new
|
33
|
+
bw.call(Wrap[text, width: 5]).must_equal Wrap[wrap, width: 5]
|
28
34
|
end
|
29
|
-
bw = BasicWrapper.new
|
30
|
-
bw.call(Wrap[text, width: 5]).must_equal Wrap[wrap, width: 5]
|
31
|
-
end
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
it 'rewraps a String from zero' do
|
37
|
+
text = <<-end.dedent
|
38
|
+
turn off
|
39
|
+
the lights and I’ll glow
|
40
|
+
end
|
41
|
+
wrap = "turn off the lights and I’ll glow\n"
|
42
|
+
BasicWrapper.new.call(Wrap[text]).must_equal Wrap[wrap]
|
37
43
|
end
|
38
|
-
wrap = "turn off the lights and I’ll glow\n"
|
39
|
-
BasicWrapper.new.call(Wrap[text]).must_equal Wrap[wrap]
|
40
|
-
end
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
it 'passes the fixed text to the next layer and returns its outcome' do
|
46
|
+
final = fake(:wrap)
|
47
|
+
layer = fake(:layer)
|
48
|
+
mock(layer).call(Wrap["I\nO\nU\n", width: 2]) { final }
|
49
|
+
BasicWrapper.new(layer).call(Wrap['I O U', width: 2]).must_equal final
|
50
|
+
end
|
47
51
|
end
|
48
52
|
end
|
49
|
-
end
|
53
|
+
end
|