sub_diff 1.0.2 → 1.0.3

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: dc9000575a6556b4b118600aa932fec2efdf92c6
4
- data.tar.gz: 0052e7df82331d0beff26bb09cf447be317ab995
3
+ metadata.gz: 00af3c2d98b709d67f09613790843c055aa6e0ac
4
+ data.tar.gz: b22a8f236b3c94147cf11cb32b6a57432df5a950
5
5
  SHA512:
6
- metadata.gz: be6f74f1cb8a5965931792a42e46a0638ff2573bb41893df7a2a4f12f7e2b8557d760b3bb80f474e0e2e8e526361e0684ea06dfd7dc084b0394955120be7608e
7
- data.tar.gz: 5f520e25084f52d1a60a1a925bfd9310b741c8a45b77e45893dcb632d6ce258e4eaa8b53ecac4435740405c89fb5c4cd5250356293b5a405719cbe9614f66d45
6
+ metadata.gz: 619fce2ea0266f758a6136bde2ca11e6f5130cd27f82487dae99963eeca2670e9cdde6b92bda802770f533d5ba92126ad50f683f1b2b36c72047614abd8de70c
7
+ data.tar.gz: f2338bcd91dfaae6f19b4bb8378202e47c39abf087cd0cc268a662d7b2788e030b4384d239e985332d84789910a9aca723c02b95b43e877daff82f3c22cba6cb
data/README.md CHANGED
@@ -88,8 +88,8 @@ end
88
88
 
89
89
  [YARD Documentation](http://www.rubydoc.info/github/shuber/sub_diff)
90
90
 
91
- * `String#gsub`
92
- * `String#sub`
91
+ * `String#sub_diff`
92
+ * `String#gsub_diff`
93
93
  * `SubDiff::Diff#changed?`
94
94
  * `SubDiff::Diff#value`
95
95
  * `SubDiff::Diff#value_was`
@@ -1,7 +1,13 @@
1
1
  module SubDiff
2
- class Builder < Struct.new(:string, :type)
2
+ class Builder
3
+ def initialize(string, type)
4
+ @string = string
5
+ @type = type
6
+ end
7
+
3
8
  def diff(*args, &block)
4
- builder.diff(*args, &block)
9
+ @collection = Collection.new(string)
10
+ adapter.diff(*args, &block)
5
11
  collection
6
12
  end
7
13
 
@@ -15,24 +21,22 @@ module SubDiff
15
21
 
16
22
  private
17
23
 
18
- def builder
19
- constant.new(differ)
24
+ attr_reader :collection, :string, :type
25
+
26
+ def adapter
27
+ adapter_class.new(differ)
20
28
  end
21
29
 
22
- def constant
23
- Module.nesting.last.const_get(constant_name)
30
+ def adapter_class
31
+ Module.nesting.last.const_get(adapter_name)
24
32
  end
25
33
 
26
- def constant_name
34
+ def adapter_name
27
35
  type.to_s.capitalize
28
36
  end
29
37
 
30
38
  def differ
31
39
  Differ.new(self, type)
32
40
  end
33
-
34
- def collection
35
- @collection ||= Collection.new(string)
36
- end
37
41
  end
38
42
  end
@@ -1,9 +1,14 @@
1
1
  module SubDiff
2
- class Differ < Struct.new(:builder, :type)
2
+ class Differ
3
3
  extend Forwardable
4
4
 
5
5
  def_delegators :builder, :string
6
6
 
7
+ def initialize(builder, type)
8
+ @builder = builder
9
+ @type = type
10
+ end
11
+
7
12
  def each_diff(*args)
8
13
  # Ruby 1.8.7 does not support additional args after * (splat)
9
14
  block = args.pop
@@ -14,5 +19,9 @@ module SubDiff
14
19
  yield(builder, diff)
15
20
  end
16
21
  end
22
+
23
+ private
24
+
25
+ attr_reader :builder, :type
17
26
  end
18
27
  end
data/lib/sub_diff/sub.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  module SubDiff
2
- class Sub < Struct.new(:differ)
2
+ class Sub
3
+ def initialize(differ)
4
+ @differ = differ
5
+ end
6
+
3
7
  def diff(*args, &block)
4
8
  # Ruby 1.8.7 does not support additional args after * (splat)
5
9
  args.push(block)
@@ -11,6 +15,8 @@ module SubDiff
11
15
 
12
16
  private
13
17
 
18
+ attr_reader :differ
19
+
14
20
  def process(builder, diff, search)
15
21
  builder << prefix(diff)
16
22
  builder.push(diff[:replacement], diff[:match])
@@ -1,3 +1,3 @@
1
1
  module SubDiff
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sub_diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Huber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-26 00:00:00.000000000 Z
11
+ date: 2015-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec