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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49c92b0710902ad7b5974120c3259511bca506b9
4
- data.tar.gz: bacdd2b6ed4093103944c30e464defca9c88fd67
3
+ metadata.gz: c850fd5f62d6480194b4a54e2bb82c5a8916935b
4
+ data.tar.gz: fdcbe2f05741001b4e8aafba0daa5f6c8fc77ed7
5
5
  SHA512:
6
- metadata.gz: 23d1be28b58049eb916bb07390880e487e81c960ad3315212de2fe396e225f695ed9f2489c3254d55efac807f88d73521d791c800b9b4211754b8d5f29978f86
7
- data.tar.gz: 4258e4a7562d74568f4c1fa2a26df4cddf9d2b93691f8582418e931ccd8904be057ba7721e5a6992fefb7f994cb897ea5091df89f655b3b60b82b965efa3cd49
6
+ metadata.gz: 3f3807f7c18e4c21d3cf0754f5655fd653bb0ff86d30e85aa749a051d9ac67e38de5377f0ebc37bf54f5fd0effe3b32fbbb6d85391cd0be8edb3f5a19f2c7e4e
7
+ data.tar.gz: 23eb91f197f1f8e78951d973a8bbd73739c92abeb01da409a096496585fbb3889061375dfcc3146d3c736cf8df8a1b2cd128312192ad4f0f69e34fa4b9924150
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lovely_rufus (0.1.2)
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.3)
17
+ ffi (1.9.6)
18
18
  hitimes (1.2.2)
19
- listen (2.7.9)
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.1)
23
+ minitest (5.4.3)
24
24
  minitest-focus (1.1.0)
25
25
  minitest (>= 4, < 6)
26
- parser (2.2.0.pre.4)
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.3.8)
35
+ reek (1.4.0)
36
36
  rainbow (>= 1.99, < 3.0)
37
37
  ruby2ruby (>= 2.0.8, < 3.0)
38
- ruby_parser (~> 3.3)
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.26.0)
42
+ rubocop (0.27.1)
43
43
  astrolabe (~> 1.3)
44
- parser (>= 2.2.0.pre.4, < 3.0)
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.5.1)
49
- ruby2ruby (2.1.2)
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.2)
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.26.0)
70
+ rubocop (~> 0.27.0)
@@ -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
@@ -2,8 +2,8 @@ module LovelyRufus
2
2
  NBSP = "\u00A0"
3
3
  QUOTES = /^([>\/#])(\1| )*/
4
4
 
5
- def self.wrap(text, width: 72)
6
- TextWrapper.wrap(text, width: width)
5
+ def self.wrap(text, text_wrapper: TextWrapper, width: 72)
6
+ text_wrapper.wrap(text, width: width)
7
7
  end
8
8
  end
9
9
 
@@ -5,9 +5,9 @@ require_relative 'wrap'
5
5
  module LovelyRufus
6
6
  class HangoutWrapper < Layer
7
7
  def call(wrap)
8
- @wrap = wrap
9
- final = hangout_line ? rewrapped : wrap.text
10
- next_layer.call(Wrap[final, width: wrap.width])
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
- 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
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.text.lines.map(&:chomp)
43
+ @lines ||= wrap.lines
29
44
  end
30
45
 
31
46
  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
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.text.lines.map { |line| fixed_quote + line }.join
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.text.lines.map { |line| line[QUOTES] }.uniq
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.text.lines.map { |line| line[quote.size..-1] }.join
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 do |opts|
8
- opts.on('-w', '--width=WIDTH', Integer, 'Wrapping width') do |width|
9
- self.width = width
10
- end
11
- end.parse! args
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
@@ -1,7 +1,13 @@
1
+ require 'forwardable'
2
+
1
3
  module LovelyRufus
2
4
  Wrap = Struct.new(:text, :width) do
5
+ extend Forwardable
6
+
3
7
  def initialize(text = '', width: 72)
4
8
  super text, width
5
9
  end
10
+
11
+ delegate lines: :text
6
12
  end
7
13
  end
@@ -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.0'
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.26.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
- wrap = <<-end.dedent
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.must_output wrap
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'
@@ -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
- it 'wraps the passed String to 72 characters by default' do
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 'wraps the passed String to the given number of characters' do
19
- input = 'something grabs a hold of me tightly; ' \
20
- 'flow like a harpoon daily and nightly'
21
- LovelyRufus.wrap(input, width: 40).must_equal <<-end.dedent
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 'rewraps a String from zero' do
34
- broken = <<-end.dedent
35
- turn off
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
@@ -9,6 +9,6 @@ Bogus.configure { |config| config.search_modules << LovelyRufus }
9
9
 
10
10
  class String
11
11
  def dedent
12
- gsub(/^#{self[/\A\s*/]}/, '')
12
+ gsub(/^#{scan(/^ +/).min}/, '')
13
13
  end
14
14
  end
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.0
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-09-11 00:00:00.000000000 Z
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.26.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.26.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: