ruby-nuggets 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.6.7
5
+ This documentation refers to ruby-nuggets version 0.6.8
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -53,7 +53,7 @@ module Enumerable
53
53
  # to their respective source. (Equivalent to <tt>agrep -k</tt>)
54
54
  # - Only works with string elements in _enum_. (Calls +to_s+ on each element)
55
55
  # - The cost for individual error types (substitution, insertion, deletion)
56
- # cannot be adjusted.
56
+ # cannot be adjusted.
57
57
  def agrep(pattern, distance = 0)
58
58
  raise 'Amatch not available!' unless defined?(Amatch)
59
59
 
@@ -0,0 +1,5 @@
1
+ require 'nuggets/file/replace_mixin'
2
+
3
+ class File
4
+ extend Nuggets::File::ReplaceMixin
5
+ end
@@ -0,0 +1,56 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of ruby-nuggets, some extensions to the Ruby programming #
5
+ # language. #
6
+ # #
7
+ # Copyright (C) 2007-2011 Jens Wille #
8
+ # #
9
+ # Authors: #
10
+ # Jens Wille <jens.wille@uni-koeln.de> #
11
+ # #
12
+ # ruby-nuggets is free software; you can redistribute it and/or modify it #
13
+ # under the terms of the GNU General Public License as published by the Free #
14
+ # Software Foundation; either version 3 of the License, or (at your option) #
15
+ # any later version. #
16
+ # #
17
+ # ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
20
+ # more details. #
21
+ # #
22
+ # You should have received a copy of the GNU General Public License along #
23
+ # with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
24
+ # #
25
+ ###############################################################################
26
+ #++
27
+
28
+ module Nuggets
29
+ class File
30
+ module ReplaceMixin
31
+
32
+ # call-seq:
33
+ # File.replace(name, create_if_missing = false) { ... } => aString
34
+ # File.replace(name, create_if_missing = false) { |content| ... } => aString
35
+ #
36
+ # Replaces the contents of file +name+ with the result of the block. Yields
37
+ # the file's contents to the block if requested. Returns the new content.
38
+ #
39
+ # If +create_if_missing+ is true and the file does not exist, it will be
40
+ # created.
41
+ def replace(name, create_if_missing = false, &block)
42
+ open(name, create_if_missing && !exist?(name) ? 'w+' : 'r+') { |f|
43
+ content = block.arity != 0 ? yield(f.read) : yield
44
+
45
+ f.truncate(0)
46
+ f.rewind
47
+
48
+ f.print content
49
+
50
+ content
51
+ }
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ require 'nuggets/file/sub_mixin'
2
+
3
+ class File
4
+ extend Nuggets::File::SubMixin
5
+ end
@@ -0,0 +1,96 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of ruby-nuggets, some extensions to the Ruby programming #
5
+ # language. #
6
+ # #
7
+ # Copyright (C) 2007-2011 Jens Wille #
8
+ # #
9
+ # Authors: #
10
+ # Jens Wille <jens.wille@uni-koeln.de> #
11
+ # #
12
+ # ruby-nuggets is free software; you can redistribute it and/or modify it #
13
+ # under the terms of the GNU General Public License as published by the Free #
14
+ # Software Foundation; either version 3 of the License, or (at your option) #
15
+ # any later version. #
16
+ # #
17
+ # ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
20
+ # more details. #
21
+ # #
22
+ # You should have received a copy of the GNU General Public License along #
23
+ # with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
24
+ # #
25
+ ###############################################################################
26
+ #++
27
+
28
+ require 'nuggets/file/replace_mixin'
29
+
30
+ module Nuggets
31
+ class File
32
+ module SubMixin
33
+
34
+ def self.extended(base)
35
+ base.extend Nuggets::File::ReplaceMixin
36
+ end
37
+
38
+ # call-seq:
39
+ # File.sub(name, *args, &block) => aString
40
+ #
41
+ # Calls String#sub! on file +name+'s contents with +args+ and (optional)
42
+ # +block+ and returns the new content.
43
+ def sub(name, *args)
44
+ content = read(name)
45
+ content.sub!(*args, &block_given? ? Proc.new : nil)
46
+ content
47
+ end
48
+
49
+ # call-seq:
50
+ # File.sub!(name, *args, &block) => aString or nil
51
+ #
52
+ # Calls String#sub! on file +name+'s contents with +args+ and (optional)
53
+ # +block+ and replaces the file with the new content. Returns the result
54
+ # of the String#sub! call.
55
+ def sub!(name, *args)
56
+ res = nil
57
+
58
+ replace(name) { |content|
59
+ res = content.sub!(*args, &block_given? ? Proc.new : nil)
60
+ content
61
+ }
62
+
63
+ res
64
+ end
65
+
66
+ # call-seq:
67
+ # File.gsub(name, *args, &block) => aString
68
+ #
69
+ # Calls String#gsub! on file +name+'s contents with +args+ and (optional)
70
+ # +block+ and returns the new content.
71
+ def gsub(name, *args)
72
+ content = read(name)
73
+ content.gsub!(*args, &block_given? ? Proc.new : nil)
74
+ content
75
+ end
76
+
77
+ # call-seq:
78
+ # File.gsub!(name, *args, &block) => aString or nil
79
+ #
80
+ # Calls String#gsub! on file +name+'s contents with +args+ and (optional)
81
+ # +block+ and replaces the file with the new content. Returns the result
82
+ # of the String#gsub! call.
83
+ def gsub!(name, *args)
84
+ res = nil
85
+
86
+ replace(name) { |content|
87
+ res = content.gsub!(*args, &block_given? ? Proc.new : nil)
88
+ content
89
+ }
90
+
91
+ res
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -43,7 +43,7 @@ class String
43
43
  }
44
44
 
45
45
  wrapped = wrapped.join
46
-
46
+
47
47
  as_array ? wrapped.split("\n") : wrapped
48
48
  end
49
49
 
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 6
7
- TINY = 7
7
+ TINY = 8
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nuggets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 7
10
- version: 0.6.7
9
+ - 8
10
+ version: 0.6.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jens Wille
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-21 00:00:00 +01:00
18
+ date: 2011-02-03 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -75,8 +75,12 @@ files:
75
75
  - lib/nuggets/enumerable/minmax.rb
76
76
  - lib/nuggets/enumerable/agrep.rb
77
77
  - lib/nuggets/tempfile/open.rb
78
+ - lib/nuggets/file/replace.rb
78
79
  - lib/nuggets/file/which.rb
80
+ - lib/nuggets/file/sub.rb
79
81
  - lib/nuggets/file/which_mixin.rb
82
+ - lib/nuggets/file/replace_mixin.rb
83
+ - lib/nuggets/file/sub_mixin.rb
80
84
  - lib/nuggets/numeric/between.rb
81
85
  - lib/nuggets/numeric/signum.rb
82
86
  - lib/nuggets/numeric/limit.rb
@@ -168,11 +172,11 @@ rdoc_options:
168
172
  - UTF-8
169
173
  - --main
170
174
  - README
175
+ - --all
171
176
  - --line-numbers
172
- - --inline-source
173
177
  - --title
174
- - ruby-nuggets Application documentation
175
- - --all
178
+ - ruby-nuggets Application documentation (v0.6.8)
179
+ - --inline-source
176
180
  require_paths:
177
181
  - lib
178
182
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -196,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
200
  requirements: []
197
201
 
198
202
  rubyforge_project: prometheus
199
- rubygems_version: 1.4.2
203
+ rubygems_version: 1.5.0
200
204
  signing_key:
201
205
  specification_version: 3
202
206
  summary: Some extensions to the Ruby programming language.