lovely-rufus 0.0.3 → 0.0.4
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 +7 -0
- data/.rubocop.yml +23 -0
- data/.ruby-version +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +27 -15
- data/README.md +1 -1
- data/Rakefile +10 -9
- data/config/reek.yml +0 -0
- data/lib/lovely-rufus.rb +1 -0
- data/lib/lovely-rufus/executable.rb +17 -9
- data/lib/lovely-rufus/wrapper.rb +67 -37
- data/lovely-rufus.gemspec +2 -6
- data/spec/lovely-rufus/executable_spec.rb +14 -20
- data/spec/lovely-rufus/wrapper_spec.rb +5 -4
- data/spec/spec_helper.rb +2 -3
- metadata +15 -81
- data/.rvmrc +0 -2
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4bc1501b91f7200aa0470d05f334d920ac46357d
|
4
|
+
data.tar.gz: f6b4a99d363210365ec476ae344804c6b8a67511
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d12aac424d760ae10388d15909c717c073af5d5e31a697c8d855606bcd5b615e7a49721229b1924a039d4d28801fa538fdf7ad519db9cdf21a89a19e200c3657
|
7
|
+
data.tar.gz: c6f3c5eff72842a91fc091e495d54f865f6b615b0240a1d86830bb9ab69dfa57128bac9a1dd3cf21082acbad1bcffa84ad21fd70559f53b99330a0e482548415
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
AccessModifierIndentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
AndOr:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
DefWithoutParentheses:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Documentation:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
EndAlignment:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
IndentationWidth:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
MethodLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
RegexpLiteral:
|
23
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,27 +1,39 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lovely-rufus (0.0.
|
4
|
+
lovely-rufus (0.0.3)
|
5
5
|
|
6
6
|
GEM
|
7
|
-
remote:
|
7
|
+
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
ast (1.1.0)
|
10
|
+
minitest (5.0.8)
|
11
|
+
parser (2.0.0)
|
12
|
+
ast (~> 1.1)
|
13
|
+
slop (~> 3.4, >= 3.4.5)
|
14
|
+
powerpack (0.0.9)
|
15
|
+
rainbow (1.1.4)
|
16
|
+
reek (1.3.4)
|
17
|
+
ruby2ruby (~> 2.0.2)
|
18
|
+
ruby_parser (~> 3.2)
|
19
|
+
sexp_processor
|
20
|
+
rubocop (0.15.0)
|
21
|
+
parser (~> 2.0)
|
22
|
+
powerpack (~> 0.0.6)
|
23
|
+
rainbow (>= 1.1.4)
|
24
|
+
ruby2ruby (2.0.6)
|
25
|
+
ruby_parser (~> 3.1)
|
26
|
+
sexp_processor (~> 4.0)
|
27
|
+
ruby_parser (3.2.2)
|
28
|
+
sexp_processor (~> 4.1)
|
29
|
+
sexp_processor (4.4.0)
|
30
|
+
slop (3.4.7)
|
17
31
|
|
18
32
|
PLATFORMS
|
19
33
|
ruby
|
20
34
|
|
21
35
|
DEPENDENCIES
|
22
|
-
bundler
|
23
36
|
lovely-rufus!
|
24
|
-
minitest (~>
|
25
|
-
|
26
|
-
|
27
|
-
rerun
|
37
|
+
minitest (~> 5.0)
|
38
|
+
reek (~> 1.3)
|
39
|
+
rubocop (~> 0.15.0)
|
data/README.md
CHANGED
@@ -67,4 +67,4 @@ Lovely Rufus was created as a [Ruby Mendicant University](http://blog.majesticse
|
|
67
67
|
|
68
68
|
---
|
69
69
|
|
70
|
-
© MMX-
|
70
|
+
© MMX-MMXIII Piotr Szotkowski <chastell@chastell.net>, licensed under AGPL 3 (see LICENCE)
|
data/Rakefile
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
require 'rake/testtask'
|
2
|
+
require 'reek/rake/task'
|
3
|
+
require 'rubocop/rake_task'
|
4
|
+
|
5
|
+
task default: %i[spec rubocop]
|
2
6
|
|
3
7
|
Rake::TestTask.new :spec do |task|
|
4
8
|
task.test_files = FileList['spec/**/*_spec.rb']
|
5
9
|
task.warning = true
|
6
10
|
end
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
task
|
12
|
-
require 'irb'
|
13
|
-
require_relative 'lib/lovely-rufus'
|
14
|
-
include LovelyRufus
|
15
|
-
ARGV.clear
|
16
|
-
IRB.start
|
12
|
+
Reek::Rake::Task.new do |task|
|
13
|
+
task.config_files = 'config/reek.yml'
|
14
|
+
task.fail_on_error = false
|
15
|
+
task.reek_opts = '--quiet'
|
17
16
|
end
|
17
|
+
|
18
|
+
Rubocop::RakeTask.new
|
data/config/reek.yml
ADDED
File without changes
|
data/lib/lovely-rufus.rb
CHANGED
@@ -1,17 +1,25 @@
|
|
1
1
|
module LovelyRufus class Executable
|
2
2
|
def initialize args = ARGV
|
3
|
-
@
|
4
|
-
OptionParser.new do |opts|
|
5
|
-
opts.on '-w', '--width WIDTH', Integer, 'Wrapping width' do |width|
|
6
|
-
@width = width
|
7
|
-
end
|
8
|
-
end.parse! args
|
3
|
+
@settings = settings_from args
|
9
4
|
end
|
10
5
|
|
11
6
|
def run input = $stdin
|
12
|
-
puts Wrapper.new(input.read).wrapped width
|
7
|
+
puts Wrapper.new(input.read).wrapped settings.width
|
13
8
|
end
|
14
9
|
|
15
|
-
attr_reader :
|
16
|
-
private :
|
10
|
+
attr_reader :settings
|
11
|
+
private :settings
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def settings_from args
|
16
|
+
Struct.new(:width).new.tap do |settings|
|
17
|
+
settings.width = 72
|
18
|
+
OptionParser.new do |opts|
|
19
|
+
opts.on '-w', '--width WIDTH', Integer, 'Wrapping width' do |width|
|
20
|
+
settings.width = width
|
21
|
+
end
|
22
|
+
end.parse! args
|
23
|
+
end
|
24
|
+
end
|
17
25
|
end end
|
data/lib/lovely-rufus/wrapper.rb
CHANGED
@@ -1,63 +1,93 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
module LovelyRufus class Wrapper
|
4
|
-
|
5
2
|
NBSP = ' '
|
6
3
|
|
7
4
|
def initialize text
|
8
|
-
@paras = text.split(
|
5
|
+
@paras = text.split(%r{\n[/#> ]*\n}).map { |para| Para.new para.strip }
|
9
6
|
end
|
10
7
|
|
11
8
|
def wrapped max_width = 72
|
12
9
|
return '' if paras.all?(&:empty?)
|
13
10
|
|
14
11
|
paras.map do |para|
|
15
|
-
|
12
|
+
para.wrap_recursively max_width
|
13
|
+
end.join "\n\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :paras
|
17
|
+
private :paras
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
class Para
|
22
|
+
def initialize text
|
23
|
+
@text = text
|
24
|
+
end
|
25
|
+
|
26
|
+
def empty?
|
27
|
+
text.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def wrap_recursively max_width
|
31
|
+
best = wrap_to_width max_width
|
16
32
|
(max_width - 1).downto 1 do |width|
|
17
|
-
shorter =
|
33
|
+
shorter = wrap_to_width width
|
18
34
|
break if shorter.lines.count > best.lines.count
|
19
35
|
break if shorter.lines.map(&:size).max > best.lines.map(&:size).max
|
20
36
|
best = shorter
|
21
37
|
end
|
22
38
|
best
|
23
|
-
end
|
24
|
-
end
|
39
|
+
end
|
25
40
|
|
26
|
-
|
27
|
-
|
41
|
+
def wrap_to_width width
|
42
|
+
quotes = text[/^([\/#> ]*)/]
|
43
|
+
leader = quotes.empty? ? '' : quotes.tr(' ', '') + ' '
|
44
|
+
width -= leader.size if width > leader.size
|
45
|
+
text.lines
|
46
|
+
.map { |line| line[quotes.size..-1] }.join # drop quotes
|
47
|
+
.tr("\n", ' ') # unwrap para
|
48
|
+
.gsub(/ ([^ ]) /, " \\1#{NBSP}") # glue 1-letter words
|
49
|
+
.gsub(/(.{1,#{width}})( |$\n?)/, "\\1\n") # wrap to width
|
50
|
+
.tap { |par| remove_hangouts par, width } # handle hangouts
|
51
|
+
.lines.map { |line| line.insert 0, leader }.join # re-insert leader
|
52
|
+
.tr(NBSP, ' ') # drop glue spaces
|
53
|
+
.chomp # final touch
|
54
|
+
end
|
28
55
|
|
29
|
-
|
56
|
+
attr_reader :text
|
57
|
+
private :text
|
30
58
|
|
31
|
-
|
32
|
-
lines = para.split "\n"
|
59
|
+
private
|
33
60
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
61
|
+
def find_hangout_line lines
|
62
|
+
lines.find.with_index do |line, i|
|
63
|
+
i < lines.size - 1 and
|
64
|
+
space = hangout_last_space(line) and
|
65
|
+
(hangout_to_previous_line i, lines, space or
|
66
|
+
hangout_to_next_line i, lines, space)
|
67
|
+
end
|
39
68
|
end
|
40
69
|
|
41
|
-
|
42
|
-
|
43
|
-
fixed = lines.join(' ').gsub "#{NBSP} ", NBSP
|
44
|
-
para.replace wrap_para_to_width fixed, width
|
70
|
+
def hangout_last_space line
|
71
|
+
line.rindex(/[ #{NBSP}]/)
|
45
72
|
end
|
46
|
-
end
|
47
73
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
.gsub(/(.{1,#{width}})( |$\n?)/, "\\1\n") # wrap to width
|
57
|
-
.tap { |par| remove_hangouts par, width } # handle hangouts
|
58
|
-
.lines.map { |line| line.insert 0, leader }.join # re-insert leader
|
59
|
-
.tr(NBSP, ' ') # drop glue spaces
|
60
|
-
.chomp # final touch
|
61
|
-
end
|
74
|
+
def hangout_to_next_line i, lines, space
|
75
|
+
(i < lines.size - 2 or lines.size == 2) and
|
76
|
+
space + 1 >= lines[i + 1].size
|
77
|
+
end
|
78
|
+
|
79
|
+
def hangout_to_previous_line i, lines, space
|
80
|
+
i > 0 and space + 1 >= lines[i - 1].size
|
81
|
+
end
|
62
82
|
|
83
|
+
def remove_hangouts para, width
|
84
|
+
lines = para.split "\n"
|
85
|
+
hangout_line = find_hangout_line lines
|
86
|
+
if hangout_line
|
87
|
+
hangout_line << NBSP
|
88
|
+
fixed = self.class.new lines.join(' ').gsub "#{NBSP} ", NBSP
|
89
|
+
para.replace fixed.wrap_to_width width
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
63
93
|
end end
|
data/lovely-rufus.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'lovely-rufus'
|
3
|
-
gem.version = '0.0.
|
3
|
+
gem.version = '0.0.4'
|
4
4
|
gem.summary = 'lovely-rufus: text wrapper'
|
5
5
|
gem.homepage = 'http://github.com/chastell/lovely-rufus'
|
6
6
|
gem.author = 'Piotr Szotkowski'
|
@@ -10,9 +10,5 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.executables = gem.files.grep(%r{^bin/}).map { |path| File.basename path }
|
11
11
|
gem.test_files = gem.files.grep %r{^spec/.*\.rb$}
|
12
12
|
|
13
|
-
gem.
|
14
|
-
gem.add_development_dependency 'minitest', '~> 4.0'
|
15
|
-
gem.add_development_dependency 'rake'
|
16
|
-
gem.add_development_dependency 'rb-inotify'
|
17
|
-
gem.add_development_dependency 'rerun'
|
13
|
+
gem.add_dependency 'lovely_rufus'
|
18
14
|
end
|
@@ -1,31 +1,25 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
require_relative '../spec_helper'
|
4
2
|
|
5
3
|
module LovelyRufus describe Executable do
|
4
|
+
describe '#run' do
|
5
|
+
it 'outputs passed text' do
|
6
|
+
text = StringIO.new 'some text'
|
7
|
+
-> { Executable.new.run text }.must_output "some text\n"
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end.first.must_equal "some text\n"
|
12
|
-
|
13
|
-
capture_io do
|
14
|
-
Executable.new(['-w', '4']).run StringIO.new 'some text'
|
15
|
-
end.first.must_equal "some\ntext\n"
|
10
|
+
it 'wraps passed text to desired width' do
|
11
|
+
text = StringIO.new 'some text'
|
12
|
+
-> { Executable.new(%w[--width 4]).run text }.must_output "some\ntext\n"
|
13
|
+
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
it 'supports short arguments' do
|
16
|
+
text = StringIO.new 'some text'
|
17
|
+
-> { Executable.new(%w[-w4]).run text }.must_output "some\ntext\n"
|
20
18
|
end
|
21
|
-
end
|
22
19
|
|
23
|
-
describe '#run' do
|
24
20
|
it 'outputs properly wrapped input' do
|
25
|
-
|
26
|
-
|
27
|
-
end.first.must_equal "some\nmore\ntext\n"
|
21
|
+
text = StringIO.new 'some more text'
|
22
|
+
-> { Executable.new(%w[-w4]).run text }.must_output "some\nmore\ntext\n"
|
28
23
|
end
|
29
24
|
end
|
30
|
-
|
31
25
|
end end
|
@@ -1,17 +1,18 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
require_relative '../spec_helper'
|
4
2
|
|
5
3
|
module LovelyRufus describe Wrapper do
|
6
4
|
describe '#wrapped' do
|
7
5
|
it 'returns properly wrapped input' do
|
8
6
|
YAML.load_file('spec/fixtures/wrapper.yml').each do |wrapping|
|
9
|
-
|
7
|
+
width = wrapping.fetch('width') { 72 }
|
8
|
+
wrapped = Wrapper.new(wrapping['input']).wrapped width
|
9
|
+
wrapped.must_equal wrapping['output']
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'silently strips trailing newlines' do
|
14
|
-
Wrapper.new("a problematic example\n").wrapped
|
14
|
+
wrapped = Wrapper.new("a problematic example\n").wrapped 13
|
15
|
+
wrapped.must_equal "a problematic\nexample"
|
15
16
|
end
|
16
17
|
|
17
18
|
it 'doesn’t breeak on email-quoted single words' do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,94 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lovely-rufus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Piotr Szotkowski
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: lovely_rufus
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
|
-
type: :
|
20
|
+
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: minitest
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '4.0'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '4.0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: rake
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: rb-inotify
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: rerun
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ! '>='
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '0'
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
24
|
+
- - '>='
|
92
25
|
- !ruby/object:Gem::Version
|
93
26
|
version: '0'
|
94
27
|
description:
|
@@ -98,13 +31,15 @@ executables:
|
|
98
31
|
extensions: []
|
99
32
|
extra_rdoc_files: []
|
100
33
|
files:
|
101
|
-
- .
|
34
|
+
- .rubocop.yml
|
35
|
+
- .ruby-version
|
102
36
|
- Gemfile
|
103
37
|
- Gemfile.lock
|
104
38
|
- LICENCE
|
105
39
|
- README.md
|
106
40
|
- Rakefile
|
107
41
|
- bin/lovely-rufus
|
42
|
+
- config/reek.yml
|
108
43
|
- lib/lovely-rufus.rb
|
109
44
|
- lib/lovely-rufus/executable.rb
|
110
45
|
- lib/lovely-rufus/wrapper.rb
|
@@ -115,28 +50,27 @@ files:
|
|
115
50
|
- spec/spec_helper.rb
|
116
51
|
homepage: http://github.com/chastell/lovely-rufus
|
117
52
|
licenses: []
|
53
|
+
metadata: {}
|
118
54
|
post_install_message:
|
119
55
|
rdoc_options: []
|
120
56
|
require_paths:
|
121
57
|
- lib
|
122
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
59
|
requirements:
|
125
|
-
- -
|
60
|
+
- - '>='
|
126
61
|
- !ruby/object:Gem::Version
|
127
62
|
version: '0'
|
128
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
64
|
requirements:
|
131
|
-
- -
|
65
|
+
- - '>='
|
132
66
|
- !ruby/object:Gem::Version
|
133
67
|
version: '0'
|
134
68
|
requirements: []
|
135
69
|
rubyforge_project:
|
136
|
-
rubygems_version:
|
70
|
+
rubygems_version: 2.0.14
|
137
71
|
signing_key:
|
138
|
-
specification_version:
|
139
|
-
summary:
|
72
|
+
specification_version: 4
|
73
|
+
summary: 'lovely-rufus: text wrapper'
|
140
74
|
test_files:
|
141
75
|
- spec/lovely-rufus/executable_spec.rb
|
142
76
|
- spec/lovely-rufus/wrapper_spec.rb
|
data/.rvmrc
DELETED