lovely_rufus 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -14
- data/config/reek.yml +7 -6
- data/lib/lovely_rufus.rb +2 -2
- data/lib/lovely_rufus/hangout_wrapper.rb +30 -12
- data/lib/lovely_rufus/quote_stripper.rb +3 -3
- data/lib/lovely_rufus/settings.rb +9 -5
- data/lib/lovely_rufus/wrap.rb +6 -0
- data/lovely_rufus.gemspec +2 -2
- data/spec/lovely_rufus/cli_wrapper_spec.rb +3 -7
- data/spec/lovely_rufus/hangout_wrapper_spec.rb +8 -0
- data/spec/lovely_rufus/wrap_spec.rb +8 -0
- data/spec/lovely_rufus_spec.rb +8 -40
- data/spec/spec_helper.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c850fd5f62d6480194b4a54e2bb82c5a8916935b
|
4
|
+
data.tar.gz: fdcbe2f05741001b4e8aafba0daa5f6c8fc77ed7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f3807f7c18e4c21d3cf0754f5655fd653bb0ff86d30e85aa749a051d9ac67e38de5377f0ebc37bf54f5fd0effe3b32fbbb6d85391cd0be8edb3f5a19f2c7e4e
|
7
|
+
data.tar.gz: 23eb91f197f1f8e78951d973a8bbd73739c92abeb01da409a096496585fbb3889061375dfcc3146d3c736cf8df8a1b2cd128312192ad4f0f69e34fa4b9924150
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lovely_rufus (0.1
|
4
|
+
lovely_rufus (0.2.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -14,16 +14,16 @@ GEM
|
|
14
14
|
celluloid (0.16.0)
|
15
15
|
timers (~> 4.0.0)
|
16
16
|
dependor (1.0.1)
|
17
|
-
ffi (1.9.
|
17
|
+
ffi (1.9.6)
|
18
18
|
hitimes (1.2.2)
|
19
|
-
listen (2.
|
19
|
+
listen (2.8.0)
|
20
20
|
celluloid (>= 0.15.2)
|
21
21
|
rb-fsevent (>= 0.9.3)
|
22
22
|
rb-inotify (>= 0.9)
|
23
|
-
minitest (5.4.
|
23
|
+
minitest (5.4.3)
|
24
24
|
minitest-focus (1.1.0)
|
25
25
|
minitest (>= 4, < 6)
|
26
|
-
parser (2.2.0.pre.
|
26
|
+
parser (2.2.0.pre.7)
|
27
27
|
ast (>= 1.1, < 3.0)
|
28
28
|
slop (~> 3.4, >= 3.4.5)
|
29
29
|
powerpack (0.0.9)
|
@@ -32,24 +32,24 @@ GEM
|
|
32
32
|
rb-fsevent (0.9.4)
|
33
33
|
rb-inotify (0.9.5)
|
34
34
|
ffi (>= 0.5.0)
|
35
|
-
reek (1.
|
35
|
+
reek (1.4.0)
|
36
36
|
rainbow (>= 1.99, < 3.0)
|
37
37
|
ruby2ruby (>= 2.0.8, < 3.0)
|
38
|
-
ruby_parser (
|
39
|
-
sexp_processor
|
38
|
+
ruby_parser (>= 3.5.0, < 4.0)
|
39
|
+
sexp_processor (~> 4.4)
|
40
40
|
rerun (0.10.0)
|
41
41
|
listen (~> 2.7, >= 2.7.3)
|
42
|
-
rubocop (0.
|
42
|
+
rubocop (0.27.1)
|
43
43
|
astrolabe (~> 1.3)
|
44
|
-
parser (>= 2.2.0.pre.
|
44
|
+
parser (>= 2.2.0.pre.7, < 3.0)
|
45
45
|
powerpack (~> 0.0.6)
|
46
46
|
rainbow (>= 1.99.1, < 3.0)
|
47
47
|
ruby-progressbar (~> 1.4)
|
48
|
-
ruby-progressbar (1.
|
49
|
-
ruby2ruby (2.1.
|
48
|
+
ruby-progressbar (1.7.0)
|
49
|
+
ruby2ruby (2.1.3)
|
50
50
|
ruby_parser (~> 3.1)
|
51
51
|
sexp_processor (~> 4.0)
|
52
|
-
ruby_parser (3.6.
|
52
|
+
ruby_parser (3.6.3)
|
53
53
|
sexp_processor (~> 4.1)
|
54
54
|
sexp_processor (4.4.4)
|
55
55
|
slop (3.6.0)
|
@@ -67,4 +67,4 @@ DEPENDENCIES
|
|
67
67
|
rake (~> 10.1)
|
68
68
|
reek (~> 1.3)
|
69
69
|
rerun (~> 0.10.0)
|
70
|
-
rubocop (~> 0.
|
70
|
+
rubocop (~> 0.27.0)
|
data/config/reek.yml
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
DuplicateMethodCall:
|
2
2
|
exclude:
|
3
3
|
- LovelyRufus::BasicWrapper#call
|
4
|
-
- LovelyRufus::HangoutWrapper#rewrapped
|
5
4
|
|
6
5
|
FeatureEnvy:
|
7
6
|
exclude:
|
8
7
|
- LovelyRufus::BasicWrapper#call
|
9
|
-
- LovelyRufus::HangoutWrapper#hangout_line
|
10
8
|
- LovelyRufus::OneLetterGluer#call
|
11
9
|
- LovelyRufus::QuoteStripper#quote
|
10
|
+
# https://github.com/troessner/reek/issues/53
|
11
|
+
- LovelyRufus::HangoutWrapper::HangoutFinder
|
12
12
|
|
13
13
|
IrresponsibleModule:
|
14
14
|
enabled: false
|
15
15
|
|
16
|
-
NestedIterators:
|
17
|
-
exclude:
|
18
|
-
- LovelyRufus#initialize
|
19
|
-
|
20
16
|
UncommunicativeVariableName:
|
21
17
|
exclude:
|
22
18
|
- LovelyRufus::HangoutWrapper#hangout_line
|
19
|
+
|
20
|
+
UtilityFunction:
|
21
|
+
exclude:
|
22
|
+
# https://github.com/troessner/reek/issues/27
|
23
|
+
- LovelyRufus::HangoutWrapper::HangoutFinder
|
data/lib/lovely_rufus.rb
CHANGED
@@ -5,9 +5,9 @@ require_relative 'wrap'
|
|
5
5
|
module LovelyRufus
|
6
6
|
class HangoutWrapper < Layer
|
7
7
|
def call(wrap)
|
8
|
-
@wrap
|
9
|
-
final
|
10
|
-
next_layer.call(
|
8
|
+
@wrap = wrap
|
9
|
+
final = hangout_line ? rewrapped : wrap
|
10
|
+
next_layer.call(final)
|
11
11
|
end
|
12
12
|
|
13
13
|
attr_reader :wrap
|
@@ -15,24 +15,42 @@ module LovelyRufus
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
+
module HangoutFinder
|
19
|
+
module_function
|
20
|
+
|
21
|
+
def between?(line_a, line_b)
|
22
|
+
last_space = line_a.chomp.rindex(/\p{space}/)
|
23
|
+
last_space and last_space >= line_b.chomp.size
|
24
|
+
end
|
25
|
+
|
26
|
+
def reverse?(line_a, line_b)
|
27
|
+
cut = line_a.chomp.rindex(/\p{space}/)
|
28
|
+
a_after = line_a[0...cut] + "\n"
|
29
|
+
b_after = line_a[(cut + 1)..-1] + line_b
|
30
|
+
b_after.chomp.rindex(/\p{space}/) > a_after.size
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
18
34
|
def hangout_line
|
19
|
-
lines.each_cons(2) do |a, b|
|
20
|
-
|
21
|
-
|
22
|
-
return b if b[/\p{space}/] and b.rindex(/\p{space}/) >= a.size
|
35
|
+
lines.each_cons(2).with_index do |(a, b), i|
|
36
|
+
if HangoutFinder.between?(a, b)
|
37
|
+
return a unless i == lines.size - 2 and HangoutFinder.reverse?(a, b)
|
23
38
|
end
|
24
39
|
end
|
25
40
|
end
|
26
41
|
|
27
42
|
def lines
|
28
|
-
@lines ||= wrap.
|
43
|
+
@lines ||= wrap.lines
|
29
44
|
end
|
30
45
|
|
31
46
|
def rewrapped
|
32
|
-
hangout_line
|
33
|
-
|
34
|
-
|
35
|
-
|
47
|
+
hangout_line[-1] = NBSP
|
48
|
+
HangoutWrapper.new.call(wrapped)
|
49
|
+
end
|
50
|
+
|
51
|
+
def wrapped
|
52
|
+
unfolded = Wrap[lines.join, width: wrap.width]
|
53
|
+
BasicWrapper.new.call(unfolded)
|
36
54
|
end
|
37
55
|
end
|
38
56
|
end
|
@@ -6,7 +6,7 @@ module LovelyRufus
|
|
6
6
|
def call(wrap)
|
7
7
|
@wrap = wrap
|
8
8
|
wrapped = next_layer.call(stripped_wrap)
|
9
|
-
quoted = wrapped.
|
9
|
+
quoted = wrapped.lines.map { |line| fixed_quote + line }.join
|
10
10
|
Wrap[quoted, width: wrapped.width + fixed_quote.size]
|
11
11
|
end
|
12
12
|
|
@@ -20,12 +20,12 @@ module LovelyRufus
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def quote
|
23
|
-
starts = wrap.
|
23
|
+
starts = wrap.lines.map { |line| line[QUOTES] }.uniq
|
24
24
|
starts.size == 1 ? starts.first || '' : ''
|
25
25
|
end
|
26
26
|
|
27
27
|
def stripped_wrap
|
28
|
-
stripped_text = wrap.
|
28
|
+
stripped_text = wrap.lines.map { |line| line[quote.size..-1] }.join
|
29
29
|
Wrap[stripped_text, width: wrap.width - fixed_quote.size]
|
30
30
|
end
|
31
31
|
end
|
@@ -4,11 +4,15 @@ module LovelyRufus
|
|
4
4
|
Settings = Struct.new(:width) do
|
5
5
|
def initialize(args)
|
6
6
|
self.width = 72
|
7
|
-
OptionParser.new
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
OptionParser.new(&method(:parse)).parse! args
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def parse(opts)
|
13
|
+
opts.on('-w', '--width=WIDTH', Integer, 'Wrapping width') do |width|
|
14
|
+
self.width = width
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
data/lib/lovely_rufus/wrap.rb
CHANGED
data/lovely_rufus.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.license = 'AGPL-3.0'
|
8
8
|
gem.name = 'lovely_rufus'
|
9
9
|
gem.summary = 'lovely_rufus: text wrapper'
|
10
|
-
gem.version = '0.2.
|
10
|
+
gem.version = '0.2.1'
|
11
11
|
|
12
12
|
gem.files = `git ls-files -z`.split("\0")
|
13
13
|
gem.executables = gem.files.grep(/^bin\//).map { |path| File.basename(path) }
|
@@ -19,5 +19,5 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_development_dependency 'rake', '~> 10.1'
|
20
20
|
gem.add_development_dependency 'reek', '~> 1.3'
|
21
21
|
gem.add_development_dependency 'rerun', '~> 0.10.0'
|
22
|
-
gem.add_development_dependency 'rubocop', '~> 0.
|
22
|
+
gem.add_development_dependency 'rubocop', '~> 0.27.0'
|
23
23
|
end
|
@@ -16,15 +16,11 @@ module LovelyRufus
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'accepts the desired width and passes it to TextWrapper' do
|
19
|
-
|
20
|
-
all right: stop,
|
21
|
-
collaborate and listen
|
22
|
-
end
|
23
|
-
stub(text_wrapper).wrap(text, width: 22) { wrap }
|
24
|
-
lambda do
|
19
|
+
capture_io do
|
25
20
|
stream = StringIO.new(text)
|
26
21
|
CLIWrapper.new(%w(--width=22), text_wrapper: text_wrapper).run stream
|
27
|
-
end
|
22
|
+
end
|
23
|
+
text_wrapper.must_have_received :wrap, [text, { width: 22 }]
|
28
24
|
end
|
29
25
|
end
|
30
26
|
end
|
@@ -25,6 +25,14 @@ module LovelyRufus
|
|
25
25
|
wrapped = HangoutWrapper.new(layer).call(Wrap["I O\nU", width: 4])
|
26
26
|
wrapped.must_equal final
|
27
27
|
end
|
28
|
+
|
29
|
+
it 'doesn’t let the last line to hang out' do
|
30
|
+
text = <<-end.dedent
|
31
|
+
Just found out the Finnish term for grammar Nazi is pilkunnussija.
|
32
|
+
Direct translation: comma fucker. You’re welcome.
|
33
|
+
end
|
34
|
+
HangoutWrapper.new.call(Wrap[text, width: 76]).text.must_equal text
|
35
|
+
end
|
28
36
|
end
|
29
37
|
end
|
30
38
|
end
|
@@ -15,6 +15,14 @@ module LovelyRufus
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
describe '#lines' do
|
19
|
+
it 'accesses the lines of the text' do
|
20
|
+
Wrap["all right: stop,\ncollaborate and listen\n"].lines.must_equal [
|
21
|
+
"all right: stop,\n", "collaborate and listen\n"
|
22
|
+
]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
18
26
|
describe '#text' do
|
19
27
|
it 'accesses the text of the Wrap' do
|
20
28
|
Wrap['Ice Ice Baby', width: 7].text.must_equal 'Ice Ice Baby'
|
data/spec/lovely_rufus_spec.rb
CHANGED
@@ -1,51 +1,19 @@
|
|
1
|
-
require 'yaml'
|
2
1
|
require_relative 'spec_helper'
|
3
2
|
require_relative '../lib/lovely_rufus'
|
4
3
|
|
5
4
|
describe LovelyRufus do
|
6
5
|
describe '.wrap' do
|
7
|
-
|
8
|
-
short = 'all right: stop, collaborate and listen'
|
9
|
-
long = short + ' – Ice is back with a brand new invention'
|
10
|
-
wrap = <<-end.dedent
|
11
|
-
all right: stop, collaborate and listen
|
12
|
-
– Ice is back with a brand new invention
|
13
|
-
end
|
14
|
-
LovelyRufus.wrap(short).must_equal "#{short}\n"
|
15
|
-
LovelyRufus.wrap(long).must_equal wrap
|
16
|
-
end
|
6
|
+
let(:text_wrapper) { fake(:text_wrapper, as: :class) }
|
17
7
|
|
18
|
-
it '
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
something grabs a hold of me tightly;
|
23
|
-
flow like a harpoon – daily and nightly
|
24
|
-
end
|
25
|
-
LovelyRufus.wrap(input, width: 21).must_equal <<-end.dedent
|
26
|
-
something grabs
|
27
|
-
a hold of me tightly;
|
28
|
-
flow like a harpoon
|
29
|
-
– daily and nightly
|
30
|
-
end
|
8
|
+
it 'offloads the wrapping to TextWrapper' do
|
9
|
+
stub(text_wrapper).wrap('Ice Ice Baby', width: 7) { "Ice Ice\nBaby\n" }
|
10
|
+
LovelyRufus.wrap('Ice Ice Baby', text_wrapper: text_wrapper, width: 7)
|
11
|
+
.must_equal "Ice Ice\nBaby\n"
|
31
12
|
end
|
32
13
|
|
33
|
-
it '
|
34
|
-
|
35
|
-
|
36
|
-
the lights and I’ll glow
|
37
|
-
end
|
38
|
-
wrapped = LovelyRufus.wrap(broken)
|
39
|
-
wrapped.must_equal "turn off the lights and I’ll glow\n"
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'supports all the example use-cases' do
|
43
|
-
path = File.expand_path('lovely_rufus/text_wrapper_spec.yml', __dir__)
|
44
|
-
YAML.load_file(path).each do |spec|
|
45
|
-
width = spec.fetch('width') { 72 }
|
46
|
-
wrap = "#{spec['output']}\n"
|
47
|
-
LovelyRufus.wrap(spec['input'], width: width).must_equal wrap
|
48
|
-
end
|
14
|
+
it 'wraps the passed String to 72 characters by default' do
|
15
|
+
LovelyRufus.wrap 'Ice Ice Baby', text_wrapper: text_wrapper
|
16
|
+
text_wrapper.must_have_received :wrap, ['Ice Ice Baby', { width: 72 }]
|
49
17
|
end
|
50
18
|
end
|
51
19
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lovely_rufus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Szotkowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bogus
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: 0.27.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
110
|
+
version: 0.27.0
|
111
111
|
description: An executable and a Ruby library for wrapping paragraphs of text.
|
112
112
|
email: chastell@chastell.net
|
113
113
|
executables:
|