lovely_rufus 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -7
  3. data/.ruby-version +1 -1
  4. data/Gemfile.lock +41 -26
  5. data/README.md +2 -2
  6. data/Rakefile +5 -6
  7. data/bin/lovely-rufus +1 -1
  8. data/config/reek.yml +7 -7
  9. data/lib/lovely_rufus.rb +9 -6
  10. data/lib/lovely_rufus/cli_wrapper.rb +1 -2
  11. data/lib/lovely_rufus/layers/basic_wrapper.rb +14 -0
  12. data/lib/lovely_rufus/layers/code_comment_stripper.rb +13 -0
  13. data/lib/lovely_rufus/layers/email_quote_stripper.rb +15 -0
  14. data/lib/lovely_rufus/layers/hangout_wrapper.rb +57 -0
  15. data/lib/lovely_rufus/layers/layer.rb +15 -0
  16. data/lib/lovely_rufus/layers/one_letter_gluer.rb +14 -0
  17. data/lib/lovely_rufus/layers/quote_stripper.rb +29 -0
  18. data/lib/lovely_rufus/text_wrapper.rb +11 -7
  19. data/lovely_rufus.gemspec +6 -4
  20. data/{spec/lovely_rufus/cli_wrapper_spec.rb → test/lovely_rufus/cli_wrapper_test.rb} +5 -5
  21. data/test/lovely_rufus/layers/basic_wrapper_test.rb +55 -0
  22. data/test/lovely_rufus/layers/code_comment_stripper_test.rb +90 -0
  23. data/test/lovely_rufus/layers/email_quote_stripper_test.rb +101 -0
  24. data/test/lovely_rufus/layers/hangout_wrapper_test.rb +40 -0
  25. data/test/lovely_rufus/layers/one_letter_gluer_test.rb +33 -0
  26. data/{spec/lovely_rufus/settings_spec.rb → test/lovely_rufus/settings_test.rb} +1 -1
  27. data/{spec/lovely_rufus/text_wrapper_spec.rb → test/lovely_rufus/text_wrapper_test.rb} +2 -2
  28. data/{spec/lovely_rufus/text_wrapper_spec.yml → test/lovely_rufus/text_wrapper_test.yml} +0 -0
  29. data/{spec/lovely_rufus/wrap_spec.rb → test/lovely_rufus/wrap_test.rb} +3 -3
  30. data/{spec/lovely_rufus_spec.rb → test/lovely_rufus_test.rb} +1 -1
  31. data/test/test_helper.rb +37 -0
  32. metadata +51 -33
  33. data/lib/lovely_rufus/basic_wrapper.rb +0 -12
  34. data/lib/lovely_rufus/hangout_wrapper.rb +0 -56
  35. data/lib/lovely_rufus/layer.rb +0 -14
  36. data/lib/lovely_rufus/one_letter_gluer.rb +0 -12
  37. data/lib/lovely_rufus/quote_stripper.rb +0 -32
  38. data/spec/lovely_rufus/basic_wrapper_spec.rb +0 -53
  39. data/spec/lovely_rufus/hangout_wrapper_spec.rb +0 -38
  40. data/spec/lovely_rufus/one_letter_gluer_spec.rb +0 -31
  41. data/spec/lovely_rufus/quote_stripper_spec.rb +0 -131
  42. data/spec/spec_helper.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c850fd5f62d6480194b4a54e2bb82c5a8916935b
4
- data.tar.gz: fdcbe2f05741001b4e8aafba0daa5f6c8fc77ed7
3
+ metadata.gz: 1b3be99e51553764b5a5005a42751f9e635f6a12
4
+ data.tar.gz: e047b3674363d4c3a1a0b9bf3a879958bae57c8b
5
5
  SHA512:
6
- metadata.gz: 3f3807f7c18e4c21d3cf0754f5655fd653bb0ff86d30e85aa749a051d9ac67e38de5377f0ebc37bf54f5fd0effe3b32fbbb6d85391cd0be8edb3f5a19f2c7e4e
7
- data.tar.gz: 23eb91f197f1f8e78951d973a8bbd73739c92abeb01da409a096496585fbb3889061375dfcc3146d3c736cf8df8a1b2cd128312192ad4f0f69e34fa4b9924150
6
+ metadata.gz: 6247aac218976d4fba0dd11bdc85d22d33c746fed1ee7b11d8bf5556817d895992507d56e281503a376d1d8acf24ab0ab2d5bbabdf2a14a675b74a3aa9df71c6
7
+ data.tar.gz: 4ab4714a2b7a0a074792399234a4161552ddb2ee3036d44f7f2d83c5d00810809ff003d8920bdf7fe328a9647af7dbb1cd6c0fe3f8b4fa57355ca36cf9230d53
@@ -1,15 +1,12 @@
1
- AndOr:
1
+ Style/AndOr:
2
2
  Enabled: false
3
3
 
4
- Documentation:
4
+ Style/Documentation:
5
5
  Enabled: false
6
6
 
7
- FileName:
7
+ Style/FileName:
8
8
  Exclude:
9
9
  - bin/lovely-rufus
10
10
 
11
- SingleLineBlockParams:
12
- Enabled: false
13
-
14
- SingleSpaceBeforeFirstArg:
11
+ Style/SingleLineBlockParams:
15
12
  Enabled: false
@@ -1 +1 @@
1
- 2.1
1
+ 2.2
@@ -1,60 +1,75 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lovely_rufus (0.2.1)
4
+ lovely_rufus (0.3.0)
5
+ private_attr (~> 1.0)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ abstract_type (0.0.7)
11
+ adamantium (0.2.0)
12
+ ice_nine (~> 0.11.0)
13
+ memoizable (~> 0.4.0)
9
14
  ast (2.0.0)
10
15
  astrolabe (1.3.0)
11
16
  parser (>= 2.2.0.pre.3, < 3.0)
12
- bogus (0.1.5)
17
+ bogus (0.1.6)
13
18
  dependor (>= 0.0.4)
14
19
  celluloid (0.16.0)
15
20
  timers (~> 4.0.0)
21
+ concord (0.1.5)
22
+ adamantium (~> 0.2.0)
23
+ equalizer (~> 0.0.9)
16
24
  dependor (1.0.1)
25
+ diff-lcs (1.2.5)
26
+ equalizer (0.0.9)
17
27
  ffi (1.9.6)
18
28
  hitimes (1.2.2)
19
- listen (2.8.0)
29
+ ice_nine (0.11.1)
30
+ listen (2.8.5)
20
31
  celluloid (>= 0.15.2)
21
32
  rb-fsevent (>= 0.9.3)
22
33
  rb-inotify (>= 0.9)
23
- minitest (5.4.3)
34
+ memoizable (0.4.2)
35
+ thread_safe (~> 0.3, >= 0.3.1)
36
+ minitest (5.5.1)
24
37
  minitest-focus (1.1.0)
25
38
  minitest (>= 4, < 6)
26
- parser (2.2.0.pre.7)
39
+ parser (2.2.0.2)
27
40
  ast (>= 1.1, < 3.0)
28
- slop (~> 3.4, >= 3.4.5)
29
- powerpack (0.0.9)
41
+ powerpack (0.1.0)
42
+ private_attr (1.0.0)
43
+ procto (0.0.2)
30
44
  rainbow (2.0.0)
31
- rake (10.3.2)
45
+ rake (10.4.2)
32
46
  rb-fsevent (0.9.4)
33
47
  rb-inotify (0.9.5)
34
48
  ffi (>= 0.5.0)
35
- reek (1.4.0)
36
- rainbow (>= 1.99, < 3.0)
37
- ruby2ruby (>= 2.0.8, < 3.0)
38
- ruby_parser (>= 3.5.0, < 4.0)
39
- sexp_processor (~> 4.4)
49
+ reek (2.0.0)
50
+ parser (~> 2.2)
51
+ rainbow (~> 2.0)
52
+ unparser (~> 0.2.2)
40
53
  rerun (0.10.0)
41
54
  listen (~> 2.7, >= 2.7.3)
42
- rubocop (0.27.1)
55
+ rubocop (0.29.0)
43
56
  astrolabe (~> 1.3)
44
- parser (>= 2.2.0.pre.7, < 3.0)
45
- powerpack (~> 0.0.6)
57
+ parser (>= 2.2.0.1, < 3.0)
58
+ powerpack (~> 0.1)
46
59
  rainbow (>= 1.99.1, < 3.0)
47
60
  ruby-progressbar (~> 1.4)
48
- ruby-progressbar (1.7.0)
49
- ruby2ruby (2.1.3)
50
- ruby_parser (~> 3.1)
51
- sexp_processor (~> 4.0)
52
- ruby_parser (3.6.3)
53
- sexp_processor (~> 4.1)
54
- sexp_processor (4.4.4)
55
- slop (3.6.0)
61
+ ruby-progressbar (1.7.1)
62
+ thread_safe (0.3.4)
56
63
  timers (4.0.1)
57
64
  hitimes
65
+ unparser (0.2.2)
66
+ abstract_type (~> 0.0.7)
67
+ adamantium (~> 0.2.0)
68
+ concord (~> 0.1.5)
69
+ diff-lcs (~> 1.2.5)
70
+ equalizer (~> 0.0.9)
71
+ parser (~> 2.2.0.2)
72
+ procto (~> 0.0.2)
58
73
 
59
74
  PLATFORMS
60
75
  ruby
@@ -65,6 +80,6 @@ DEPENDENCIES
65
80
  minitest (~> 5.0)
66
81
  minitest-focus (~> 1.1)
67
82
  rake (~> 10.1)
68
- reek (~> 1.3)
83
+ reek (~> 2.0)
69
84
  rerun (~> 0.10.0)
70
- rubocop (~> 0.27.0)
85
+ rubocop (~> 0.29.0)
data/README.md CHANGED
@@ -58,10 +58,10 @@ Currently, Lovely Rufus sports the following features:
58
58
  Name and history
59
59
  ----------------
60
60
 
61
- Lovely Rufus was created as a [Ruby Mendicant University](http://blog.majesticseacreature.com/tag/rubymendicant) project and is named after [a certain _Love Actually_ character](http://en.wikipedia.org/wiki/Love_Actually#Rufus) who’s [exceptionally good at wrapping](http://www.youtube.com/watch?v=W6E1wPwOaE4).
61
+ Lovely Rufus was created as a [Ruby Mendicant University](http://blog.majesticseacreature.com/tag/rubymendicant) project and is named after [a certain _Love Actually_ character](http://en.wikipedia.org/wiki/Love_Actually#Rufus) who’s [exceptionally good at wrapping](https://www.youtube.com/watch?v=E3rB_qx0wRM).
62
62
 
63
63
 
64
64
 
65
65
  ---
66
66
 
67
- © MMX-MMXIV Piotr Szotkowski <chastell@chastell.net>, licensed under AGPL-3.0 (see LICENCE)
67
+ © MMX-MMXV Piotr Szotkowski <chastell@chastell.net>, licensed under AGPL-3.0 (see LICENCE)
data/Rakefile CHANGED
@@ -2,17 +2,16 @@ require 'rake/testtask'
2
2
  require 'reek/rake/task'
3
3
  require 'rubocop/rake_task'
4
4
 
5
- task default: %i(spec rubocop reek)
5
+ task default: %i(test rubocop reek)
6
6
 
7
- Rake::TestTask.new(:spec) do |task|
8
- task.test_files = FileList['spec/**/*_spec.rb']
9
- task.warning = true
7
+ Rake::TestTask.new do |task|
8
+ task.pattern = 'test/**/*_test.rb'
9
+ task.warning = true
10
10
  end
11
11
 
12
12
  Reek::Rake::Task.new do |task|
13
- task.config_files = 'config/reek.yml'
13
+ task.config_file = 'config/reek.yml'
14
14
  task.fail_on_error = false
15
- task.reek_opts = '--quiet'
16
15
  end
17
16
 
18
17
  RuboCop::RakeTask.new do |task|
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative '../lib/lovely_rufus'
3
+ require_relative '../lib/lovely_rufus/cli_wrapper'
4
4
 
5
5
  LovelyRufus::CLIWrapper.new.run
@@ -1,23 +1,23 @@
1
1
  DuplicateMethodCall:
2
2
  exclude:
3
- - LovelyRufus::BasicWrapper#call
3
+ - LovelyRufus::Layers::BasicWrapper#call
4
4
 
5
5
  FeatureEnvy:
6
6
  exclude:
7
- - LovelyRufus::BasicWrapper#call
8
- - LovelyRufus::OneLetterGluer#call
9
- - LovelyRufus::QuoteStripper#quote
7
+ - LovelyRufus::Layers::BasicWrapper#call
8
+ - LovelyRufus::Layers::OneLetterGluer#call
9
+ - LovelyRufus::Layers::QuoteStripper#quote
10
10
  # https://github.com/troessner/reek/issues/53
11
- - LovelyRufus::HangoutWrapper::HangoutFinder
11
+ - LovelyRufus::Layers::HangoutWrapper::HangoutFinder
12
12
 
13
13
  IrresponsibleModule:
14
14
  enabled: false
15
15
 
16
16
  UncommunicativeVariableName:
17
17
  exclude:
18
- - LovelyRufus::HangoutWrapper#hangout_line
18
+ - LovelyRufus::Layers::HangoutWrapper#hangout_line
19
19
 
20
20
  UtilityFunction:
21
21
  exclude:
22
22
  # https://github.com/troessner/reek/issues/27
23
- - LovelyRufus::HangoutWrapper::HangoutFinder
23
+ - LovelyRufus::Layers::HangoutWrapper::HangoutFinder
@@ -1,11 +1,14 @@
1
+ require 'private_attr'
2
+ Class.include PrivateAttr
3
+
4
+ require_relative 'lovely_rufus/text_wrapper'
5
+
1
6
  module LovelyRufus
2
- NBSP = "\u00A0"
3
- QUOTES = /^([>\/#])(\1| )*/
7
+ NBSP = "\u00A0"
4
8
 
5
- def self.wrap(text, text_wrapper: TextWrapper, width: 72)
9
+ module_function
10
+
11
+ def wrap(text, text_wrapper: TextWrapper, width: 72)
6
12
  text_wrapper.wrap(text, width: width)
7
13
  end
8
14
  end
9
-
10
- require_relative 'lovely_rufus/cli_wrapper'
11
- require_relative 'lovely_rufus/text_wrapper'
@@ -12,7 +12,6 @@ module LovelyRufus
12
12
  puts text_wrapper.wrap(stream.read, width: settings.width)
13
13
  end
14
14
 
15
- attr_reader :settings, :text_wrapper
16
- private :settings, :text_wrapper
15
+ private_attr_reader :settings, :text_wrapper
17
16
  end
18
17
  end
@@ -0,0 +1,14 @@
1
+ require_relative '../wrap'
2
+ require_relative 'layer'
3
+
4
+ module LovelyRufus
5
+ module Layers
6
+ class BasicWrapper < Layer
7
+ def call(wrap)
8
+ unwrapped = wrap.text.tr("\n", ' ').strip
9
+ wrapped = unwrapped.gsub(/(.{1,#{wrap.width}})( |$\n?)/, "\\1\n")
10
+ next_layer.call(Wrap[wrapped, width: wrap.width])
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'quote_stripper'
2
+
3
+ module LovelyRufus
4
+ module Layers
5
+ class CodeCommentStripper < QuoteStripper
6
+ QUOTES = %r{^\s*(//|#) }
7
+
8
+ private
9
+
10
+ alias_method :fixed_quote, :quote
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'quote_stripper'
2
+
3
+ module LovelyRufus
4
+ module Layers
5
+ class EmailQuoteStripper < QuoteStripper
6
+ QUOTES = /^>[> ]*/
7
+
8
+ private
9
+
10
+ def fixed_quote
11
+ quote.size > 0 ? quote.delete(' ') + ' ' : ''
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ require_relative '../wrap'
2
+ require_relative 'basic_wrapper'
3
+ require_relative 'layer'
4
+
5
+ module LovelyRufus
6
+ module Layers
7
+ class HangoutWrapper < Layer
8
+ def call(wrap)
9
+ @wrap = wrap
10
+ final = hangout_line ? rewrapped : wrap
11
+ next_layer.call(final)
12
+ end
13
+
14
+ private_attr_reader :wrap
15
+
16
+ private
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
+
34
+ def hangout_line
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)
38
+ end
39
+ end
40
+ end
41
+
42
+ def lines
43
+ @lines ||= wrap.lines
44
+ end
45
+
46
+ def rewrapped
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)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ module LovelyRufus
2
+ module Layers
3
+ class Layer
4
+ def initialize(next_layer = -> (wrap) { wrap })
5
+ @next_layer = next_layer
6
+ end
7
+
8
+ def call(_wrap)
9
+ fail 'Layer subclasses must define #call that takes a Wrap'
10
+ end
11
+
12
+ private_attr_reader :next_layer
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require_relative '../wrap'
2
+ require_relative 'layer'
3
+
4
+ module LovelyRufus
5
+ module Layers
6
+ class OneLetterGluer < Layer
7
+ def call(wrap)
8
+ pattern = /(?<=\p{space})(&|\p{letter})\p{space}/
9
+ text = wrap.text.gsub(pattern, "\\1\\2#{NBSP}")
10
+ next_layer.call(Wrap[text, width: wrap.width])
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../wrap'
2
+ require_relative 'layer'
3
+
4
+ module LovelyRufus
5
+ module Layers
6
+ class QuoteStripper < Layer
7
+ def call(wrap)
8
+ @wrap = wrap
9
+ wrapped = next_layer.call(stripped_wrap)
10
+ quoted = wrapped.lines.map { |line| fixed_quote + line }.join
11
+ Wrap[quoted, width: wrapped.width + fixed_quote.size]
12
+ end
13
+
14
+ private_attr_reader :wrap
15
+
16
+ private
17
+
18
+ def quote
19
+ starts = wrap.lines.map { |line| line[self.class::QUOTES] }.uniq
20
+ starts.size == 1 ? starts.first || '' : ''
21
+ end
22
+
23
+ def stripped_wrap
24
+ stripped_text = wrap.lines.map { |line| line[quote.size..-1] }.join
25
+ Wrap[stripped_text, width: wrap.width - fixed_quote.size]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,11 +1,14 @@
1
- require_relative 'basic_wrapper'
2
- require_relative 'hangout_wrapper'
3
- require_relative 'one_letter_gluer'
4
- require_relative 'quote_stripper'
1
+ require_relative 'layers/basic_wrapper'
2
+ require_relative 'layers/code_comment_stripper'
3
+ require_relative 'layers/email_quote_stripper'
4
+ require_relative 'layers/hangout_wrapper'
5
+ require_relative 'layers/one_letter_gluer'
5
6
  require_relative 'wrap'
6
7
 
7
8
  module LovelyRufus
8
9
  class TextWrapper
10
+ QUOTES = /^([>\/#])(\1| )*/
11
+
9
12
  def self.wrap(text, width: 72)
10
13
  new(Wrap[text, width: width]).call
11
14
  end
@@ -20,13 +23,14 @@ module LovelyRufus
20
23
  end.join("\n")
21
24
  end
22
25
 
23
- attr_reader :wrap
24
- private :wrap
26
+ private_attr_reader :wrap
25
27
 
26
28
  private
27
29
 
28
30
  def chain
29
- layers = [QuoteStripper, OneLetterGluer, BasicWrapper, HangoutWrapper]
31
+ layers = [Layers::CodeCommentStripper, Layers::EmailQuoteStripper,
32
+ Layers::OneLetterGluer, Layers::BasicWrapper,
33
+ Layers::HangoutWrapper]
30
34
  identity = -> (wrap) { wrap }
31
35
  layers.reverse.reduce(identity) { |inner, outer| outer.new(inner) }
32
36
  end