stringray 1 → 2

Sign up to get free protection for your applications and to get access to all the features.
data/.manifest CHANGED
@@ -1,4 +1,3 @@
1
- lib/spec/rake/verify_ratio.rb
2
1
  lib/stringray.rb
3
2
  Rakefile
4
3
  README.mkdn
@@ -31,9 +31,9 @@ merged.
31
31
  Requirements
32
32
  ------------
33
33
 
34
- To run git-blog, you need... nothing!
34
+ To use StringRay, you need... nothing!
35
35
 
36
- To develop and contribute to git-blog, you also need:
36
+ To develop and contribute to StringRay, however, you need:
37
37
 
38
38
  * `gem install rake`
39
39
  * `gem install rspec`
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  ($:.unshift File.expand_path(File.join( File.dirname(__FILE__), 'lib' ))).uniq!
2
2
  require 'stringray'
3
- require 'merb-extlib/string' # String#/, because I'm a lazy fuck.
3
+ require 'extlib/string' # String#/, because I'm a lazy fuck.
4
4
  require 'rake'
5
- require 'rake/rdoctask'
5
+ require 'yard'
6
+ require 'yard/rake/yardoc_task'
6
7
  require 'spec/rake/spectask'
7
8
  require 'spec/rake/verify_rcov'
8
- require 'spec/rake/verify_ratio'
9
9
 
10
10
  begin
11
11
  require 'echoe'
@@ -25,7 +25,7 @@ begin
25
25
  desc 'tests packaged files to ensure they are all present'
26
26
  task :verify => :package do
27
27
  # An error message will be displayed if files are missing
28
- if system %(ruby -e "require 'rubygems'; require 'merb-core'; require 'pkg/merb_strokedb-#{Merb::Orms::StrokeDB::VERSION}/lib/merb_strokedb'")
28
+ if system %(ruby -e "require 'rubygems'; require 'pkg/stringray-#{StringRay::VERSION}/lib/stringray'")
29
29
  puts "\nThe library files are present"
30
30
  end
31
31
  end
@@ -71,12 +71,9 @@ ensure
71
71
  end
72
72
 
73
73
  RCov::VerifyTask.new(:verify) do |t|
74
- t.threshold = 100
74
+ t.threshold = 95
75
75
  t.index_html = 'meta' / 'coverage' / 'index.html'
76
- end
77
-
78
- Spec::Rake::VerifySpecRatioTask.new(:ratio) do |t|
79
- t.ratio = 1.00
76
+ t.require_exact_threshold = false
80
77
  end
81
78
 
82
79
  task :open do
@@ -84,15 +81,39 @@ ensure
84
81
  end
85
82
  end
86
83
 
84
+ namespace :yard do
85
+ YARD::Rake::YardocTask.new :generate do |t|
86
+ t.files = ['lib/**/*.rb']
87
+ t.options = ['--output-dir', "meta/documentation"]
88
+ end
89
+
90
+ YARD::Rake::YardocTask.new :dot_yardoc do |t|
91
+ t.files = ['lib/**/*.rb']
92
+ t.options = ['--no-output']
93
+ end
94
+
95
+ task :open do
96
+ system 'open ' + 'meta' / 'documentation' / 'index.html' if PLATFORM['darwin']
97
+ end
98
+ end
99
+
87
100
  namespace :git do
88
101
  task :status do
89
102
  `git status`
90
103
  end
104
+
105
+ task :commit => [:'echoe:manifest', :'yard:dot_yardoc'] do
106
+ `git commit`
107
+ end
108
+ end
109
+
110
+ task :clobber => [:'echoe:clobber_package', :'echoe:clobber_docs', :'echoe:clobber_coverage'] do
111
+ rm_f 'meta'
91
112
  end
92
113
 
93
114
  desc 'Check everything over before commiting'
94
- task :aok => [:'echoe:manifest', :'rcov:run', :'rcov:verify', :'rcov:ratio', :'rcov:open', :'git:status']
115
+ task :aok => [:'yard:generate', :'yard:open', :'echoe:manifest', :'rcov:run', :'rcov:verify', :'rcov:open', :'git:status']
95
116
 
96
117
  # desc 'Task run during continuous integration' # Invisible
97
- task :cruise => [:'rcov:plain', :'rcov:verify', :'rcov:ratio']
118
+ task :cruise => [:'yard:generate', :'rcov:plain', :'rcov:verify', :'rcov:ratio']
98
119
  end
@@ -1,18 +1,18 @@
1
1
 
2
- # Gem::Specification for Stringray-1
2
+ # Gem::Specification for Stringray-2
3
3
  # Originally generated by Echoe
4
4
 
5
5
  --- !ruby/object:Gem::Specification
6
6
  name: stringray
7
7
  version: !ruby/object:Gem::Version
8
- version: "1"
8
+ version: "2"
9
9
  platform: ruby
10
10
  authors:
11
11
  - elliottcable
12
12
  autorequire:
13
13
  bindir: bin
14
14
 
15
- date: 2008-08-11 00:00:00 -08:00
15
+ date: 2008-08-15 00:00:00 -08:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -33,11 +33,9 @@ executables: []
33
33
  extensions: []
34
34
 
35
35
  extra_rdoc_files:
36
- - lib/spec/rake/verify_ratio.rb
37
36
  - lib/stringray.rb
38
37
  - README.mkdn
39
38
  files:
40
- - lib/spec/rake/verify_ratio.rb
41
39
  - lib/stringray.rb
42
40
  - Rakefile
43
41
  - README.mkdn
@@ -1,128 +1,227 @@
1
1
  module StringRay
2
- VERSION = 1
2
+ VERSION = 2
3
3
 
4
- # Splits a string into words. Not using the obvious names (+#split+, +#words+)
5
- # because I want compatibility for inclusion into +String+.
6
- def enumerate
4
+ @@whitespace = nil
5
+ @@delemiters = nil
6
+
7
+ ##
8
+ # @see #enumerate
9
+ # Controls how +#enumerate+ deals with whitespace.
10
+ #
11
+ # @param [Symbol] whitespace How to handle whitespace - :attach_before,
12
+ # :standalone, or :attach_after
13
+ def self.whitespace= whitespace
14
+ @@whitespace = whitespace
15
+ end
16
+
17
+ def self.whitespace
18
+ @@whitespace ||= :attach_before
19
+ end
20
+
21
+ ##
22
+ # @see #enumerate
23
+ # Controls how +#enumerate+ deals with delemiters.
24
+ #
25
+ # @param [Symbol] delemiters How to handle delemiters - :attach_before,
26
+ # :standalone, or :attach_after
27
+ def self.delemiters= delemiters
28
+ @@delemiters = delemiters
29
+ end
30
+
31
+ def self.delemiters
32
+ @@delemiters ||= :attach_before
33
+ end
34
+
35
+ ##
36
+ # Splits a string into an array of +StringRay+ container objects (+Word+,
37
+ # +Whitespace+, and +Delimiter+).
38
+ #
39
+ # @yield [element] Allows each 'element' of the string to be operated on
40
+ # after it is processed
41
+ # @yieldparam [Word, Whitespace, Delimiter] element The last processed
42
+ # string 'element'
43
+ # @return [Array[Word, Whitespace, Delimiter]] An array of +StringRay+
44
+ # container objects
45
+ # @since 2
46
+ def to_stray
7
47
  ray = []
48
+ new_element = lambda do |element|
49
+ yield ray.last if block_given? unless ray.empty?
50
+ ray << element
51
+ end
8
52
 
9
- self.each_byte do |byte|
10
- char = byte.chr
11
-
53
+ self.scan(/./um) do |char|
12
54
  if Delimiter::Characters.include? char
13
- ray << Delimiter.new(char)
55
+ new_element[Delimiter.new(char)]
14
56
 
15
57
  elsif Whitespace::Characters.include? char
16
58
  if ray.last.is_a? Whitespace
17
59
  ray.last << char
18
60
  else
19
- ray << Whitespace.new(char)
61
+ new_element[Whitespace.new(char)]
20
62
  end
21
63
 
22
64
  else
23
65
  if ray.last.is_a? Word
24
66
  ray.last << char
25
67
  else
26
- ray << Word.new(char)
68
+ new_element[Word.new(char)]
27
69
  end
28
70
 
29
71
  end
30
72
  end
31
73
 
32
- ray
74
+ if block_given?
75
+ yield ray.last
76
+ self
77
+ else
78
+ ray
79
+ end
33
80
  end
34
81
 
35
- # More sensible than +String#each+, this uses +#enumerate+ to enumerate on
36
- # words. Accepts options as a hash, determining whether :whitespace and
37
- # :delemiters will :attach_before, :standalone, or :attach_after. Default is
38
- # for both to :attach_before.
39
- def each_word opts = {}, &block
40
- {:whitespace => :attach_before, :delemiters => :attach_before}.merge! opts
41
-
42
- # First, we create a two-dimensional array of words with any whitespace or
43
- # delemiters that should attach to them.
44
- words = self.enumerate
82
+ ##
83
+ # @see #to_stray
84
+ # @see #whitespace
85
+ # @see #delemiters
86
+ # Enumerates a string, similar to +#to_stray+, but returning an array of
87
+ # plain +String+s instead of container objects.
88
+ #
89
+ # @param [Hash] options A hash of options
90
+ # @yield [word] Allows each word in the string to be operated on after it is
91
+ # processed
92
+ # @yieldparam [String] word The last processed word
93
+ # @return [Array[String]] An array of words
94
+ # @since 1
95
+ def enumerate options = {}, &block
45
96
  mapped = []
46
97
  attach_before_next = []
47
98
 
48
- words.each do |item|
49
- case item
99
+ self.to_stray do |element|
100
+ case element
50
101
  when Delimiter
51
- case opts[:delemiters]
102
+ case options[:delemiters] || StringRay::delemiters
52
103
  when :standalone
53
- mapped << [item]
104
+ mapped << [element]
54
105
  when :attach_after
55
- attach_before_next << item
106
+ attach_before_next << element
56
107
  else
57
108
  if attach_before_next.empty?
58
- mapped.last << item
109
+ if mapped.last
110
+ mapped.last << element
111
+ else
112
+ attach_before_next << element
113
+ end
59
114
  else
60
- attach_before_next << item
115
+ attach_before_next << element
61
116
  end
62
117
  end
63
118
 
64
119
  when Whitespace
65
- case opts[:whitespace]
120
+ case options[:whitespace] || StringRay::whitespace
66
121
  when :standalone
67
- mapped << [item]
122
+ mapped << [element]
68
123
  when :attach_after
69
- attach_before_next << item
124
+ attach_before_next << element
70
125
  else
71
126
  if attach_before_next.empty?
72
- mapped.last << item
127
+ if mapped.last
128
+ mapped.last << element
129
+ else
130
+ attach_before_next << element
131
+ end
73
132
  else
74
- attach_before_next << item
133
+ attach_before_next << element
75
134
  end
76
135
  end
77
136
 
78
137
  when Word
79
138
  if not attach_before_next.empty?
80
- mapped << [attach_before_next, item].flatten
139
+ mapped << [attach_before_next, element].flatten
81
140
  attach_before_next = []
82
141
  else
83
- mapped << [item]
142
+ mapped << [element]
84
143
  end
85
144
 
86
145
  end
87
146
  end
88
- (mapped.last << attach_before_next).flatten! if not attach_before_next.empty?
89
147
 
90
- # Next, we yield each group of (word plus delimiters and whitespace) as a
91
- # normal string to the block
92
- mapped.each do |arr|
93
- yield arr.map{|w|w.to_s}.join
148
+ if not attach_before_next.empty?
149
+ mapped << [Word.new] unless mapped.last
150
+ (mapped.last << attach_before_next).flatten!
151
+ end
152
+
153
+ mapped.map do |arr|
154
+ string = arr.map{|w|w.to_s}.join
155
+ yield string if block_given?
156
+ string
94
157
  end
95
158
  end
96
159
 
160
+ # @deprecated
161
+ alias_method :each_word, :enumerate
162
+
163
+ # @see StringRay::Word#new
164
+ def Word word; Word.new word; end
165
+
166
+ ##
167
+ # A wrapper class for strings that are 'words' in and of themselves,
168
+ # composed of 'word characters'.
97
169
  class Word < String
98
170
  def inspect
99
171
  "(#{self})"
100
172
  end
101
173
  end
102
174
 
175
+ # @see StringRay::Whitespace#new
176
+ def Whitespace whitespace; Whitespace.new whitespace; end
177
+
178
+ ##
179
+ # A wrapper class for strings that are 'whitespace' composed of 'whitespace
180
+ # characters'.
103
181
  class Whitespace < String
104
182
  Characters = [" ", "\t", "\n"]
183
+
105
184
  def inspect
106
185
  "#{self}"
107
186
  end
108
187
  end
109
188
 
189
+ # @see StringRay::Delimiter#new
190
+ def Delimiter delimiter; Delimiter.new delimiter; end
191
+
192
+ ##
193
+ # A wrapper class for strings that are 'delimiters' composed of 'delimiter
194
+ # characters'.
110
195
  class Delimiter < String
111
- Characters = ['-', ',', '.', '?', '!']
196
+ Characters = ['-', ',', '.', '?', '!', ':', ';', '/', '\\', '|']
112
197
 
113
198
  def inspect
114
199
  "<#{self}>"
115
200
  end
116
201
  end
117
202
 
118
- # This overrides +String#each+ with +StringRay#each_word+, thus allowing us
119
- # to include +Enumerable+.
120
- def self.included klass
121
- klass.class_eval do
122
- alias_method :each_at, :each
123
- alias_method :each, :each_word
124
-
125
- include Enumerable
203
+ # This is mixed into any class including +StringRay+. It exposes
204
+ # +::make_enumerable!+ to said class.
205
+ module Extendables
206
+
207
+ ##
208
+ # This overrides +String#each+ with +StringRay#enumerate+, thus allowing
209
+ # us to include +Enumerable+. Be careful, this breaks lots of existing
210
+ # code which depends on the old methodology of +String#each+! The
211
+ # overridden +String#each+ functionality will be exposed as
212
+ # +String#each_at+.
213
+ def make_enumerable!
214
+ self.class_eval do
215
+ alias_method :each_at, :each
216
+ alias_method :each, :enumerate
217
+
218
+ include Enumerable
219
+ end
126
220
  end
221
+
222
+ end
223
+
224
+ def self.included klass
225
+ klass.send :extend, Extendables
127
226
  end
128
227
  end
@@ -1,75 +1,173 @@
1
+ ($:.unshift File.expand_path(File.join( File.dirname(__FILE__), '..', 'lib' ))).uniq!
1
2
  require 'stringray'
2
3
 
4
+ # Some shortcusts, because the author is a lazy typist...
5
+ def Word word; StringRay::Word.new word; end
6
+ def Whitespace whitespace; StringRay::Whitespace.new whitespace; end
7
+ def Delimiter delimiter; StringRay::Delimiter.new delimiter; end
8
+ Space = Whitespace ' '
9
+ Period = Delimiter '.'
10
+
3
11
  describe 'a String including StringRay' do
4
12
  before :all do
5
- String.send :include, StringRay
13
+ class String
14
+ include StringRay
15
+ end
6
16
  end
7
17
 
8
- describe '#enumerate' do
9
- it 'should split a string into an array' do
10
- string = 'The time has come to talk of many things - of sailing ' +
11
- 'ships and sealing wax, of cabbages and kings!'
12
- array = []
13
- string.each {|i| array << i }
14
- array.should == ['The ','time ','has ','come ','to ','talk ','of ',
15
- 'many ','things - ','of ','sailing ','ships ','and ','sealing ',
16
- 'wax, ','of ','cabbages ','and ','kings!']
18
+ describe "#to_stray" do
19
+ it "should return a multi-dimensional array of container elements" do
20
+ string = 'This is a string.'
21
+ string.to_stray.should ==
22
+ [Word('This'), Space, Word('is'), Space, Word('a'), Space, Word('string'), Period]
23
+ end
24
+
25
+ it "should yield each text element if passed a block" do
26
+ string = 'This is a string.'
27
+
28
+ yielded = []
29
+ string.to_stray do |element|
30
+ yielded << element
31
+ end
32
+
33
+ yielded.should ==
34
+ [Word('This'), Space, Word('is'), Space, Word('a'), Space, Word('string'), Period]
17
35
  end
18
36
  end
19
37
 
20
- describe '#each_word' do
21
- it 'should be able to attach delimeters to the beginning of the next word' do
22
- string = 'The time has come to talk of many things - of sailing ' +
23
- 'ships and sealing wax, of cabbages and kings!'
24
- array = []
25
- string.each(:delemiters => :attach_after) {|i| array << i }
26
- array.should == ['The ','time ','has ','come ','to ','talk ','of ',
27
- 'many ','things ','- of ','sailing ','ships ','and ','sealing ',
28
- 'wax',', of ','cabbages ','and ','kings!']
38
+ describe '#enumerate' do
39
+ it 'should split a string into an array' do
40
+ string = 'This is a string'
41
+ string.enumerate.should ==
42
+ ['This ','is ','a ','string']
29
43
  end
30
44
 
31
- it 'should be able to let delimeters stand alone' do
32
- string = 'The time has come to talk of many things - of sailing ' +
33
- 'ships and sealing wax, of cabbages and kings!'
34
- array = []
35
- string.each(:delemiters => :standalone) {|i| array << i }
36
- array.should == ['The ','time ','has ','come ','to ','talk ','of ',
37
- 'many ','things ','- ', 'of ','sailing ','ships ','and ','sealing ',
38
- 'wax',', ','of ','cabbages ','and ','kings','!']
45
+ it 'should correctly treat commas and lists' do
46
+ string = 'Commas, commas, commas'
47
+ string.enumerate.should ==
48
+ ['Commas, ','commas, ','commas']
39
49
  end
40
50
 
41
- it 'should be able to attach whitespace to the beginning of the next word' do
42
- string = 'The time has come to talk of many things - of sailing ' +
43
- 'ships and sealing wax, of cabbages and kings!'
44
- array = []
45
- string.each(:whitespace => :attach_after) {|i| array << i }
46
- array.should == ['The',' time',' has',' come',' to',' talk',' of',
47
- ' many',' things',' - of',' sailing',' ships',' and',' sealing',
48
- ' wax,',' of',' cabbages',' and',' kings!']
51
+ it 'should correctly treat periods and end-of-sentence demarcators' do
52
+ string = 'Punctuation. Cool right? Yah!'
53
+ string.enumerate.should ==
54
+ ['Punctuation. ','Cool ','right? ','Yah!']
49
55
  end
50
56
 
51
- it 'should be able to let whitespace stand alone' do
52
- string = 'The time has come to talk of many things - of sailing ' +
53
- 'ships and sealing wax, of cabbages and kings!'
54
- array = []
55
- string.each(:whitespace => :standalone) {|i| array << i }
56
- array.should == ['The',' ','time',' ','has',' ','come',' ','to',' ','talk',' ','of',
57
- ' ','many',' ','things',' -',' ','of',' ','sailing',' ','ships',' ','and',' ','sealing',
58
- ' ','wax,',' ','of',' ','cabbages',' ','and',' ','kings!']
57
+ it 'should correctly treat dahses' do
58
+ string = 'I have - uh - dashes'
59
+ string.enumerate.should ==
60
+ ['I ','have - ','uh - ','dashes']
59
61
  end
60
62
 
61
- it 'should be able to not split a delimated word' do
62
- pending "Figure out a way to allow delemiters to _not_ split words " +
63
- "- i.e. 'K-I-S-S-I-N-G' should be passed as a single word."
63
+ it 'should correctly treat ellipses' do
64
+ string = 'Where... are we... going'
65
+ string.enumerate.should ==
66
+ ['Where... ','are ','we... ','going']
67
+ end
68
+
69
+ it 'should correctly treat a delimated word' do
70
+ string = 'Pneumono-ultra-microscopic-silico-volcano-koniosis'
71
+ string.enumerate.should ==
72
+ ['Pneumono-','ultra-','microscopic-','silico-','volcano-','koniosis']
73
+ end
74
+
75
+ it 'should correctly treat inline line returns' do
76
+ string = "Line\nreturns\nyay"
77
+ string.enumerate.should ==
78
+ ["Line\n","returns\n","yay"]
79
+ end
80
+
81
+ it 'should correctly treat prefacing line returns and whitespace' do
82
+ string = "\n\t # Code\n\n"
83
+ string.enumerate.should ==
84
+ ["\n\t # ","Code\n\n"]
85
+ end
86
+
87
+ describe '(method options hash)' do
88
+ it 'should be able to attach delimeters to the beginning of the next word' do
89
+ string = 'The time has come to talk of many things - of sailing ' +
90
+ 'ships and sealing wax, of cabbages and kings!'
91
+ string.enumerate(:delemiters => :attach_after).should ==
92
+ ['The ','time ','has ','come ','to ','talk ','of ',
93
+ 'many ','things ','- of ','sailing ','ships ','and ','sealing ',
94
+ 'wax',', of ','cabbages ','and ','kings!']
95
+ end
96
+
97
+ it 'should be able to let delimeters stand alone' do
98
+ string = 'The time has come to talk of many things - of sailing ' +
99
+ 'ships and sealing wax, of cabbages and kings!'
100
+ string.enumerate(:delemiters => :standalone).should ==
101
+ ['The ','time ','has ','come ','to ','talk ','of ',
102
+ 'many ','things ','- ', 'of ','sailing ','ships ','and ','sealing ',
103
+ 'wax',', ','of ','cabbages ','and ','kings','!']
104
+ end
105
+
106
+ it 'should be able to attach whitespace to the beginning of the next word' do
107
+ string = 'The time has come to talk of many things - of sailing ' +
108
+ 'ships and sealing wax, of cabbages and kings!'
109
+ string.enumerate(:whitespace => :attach_after).should ==
110
+ ['The',' time',' has',' come',' to',' talk',' of',
111
+ ' many',' things',' - of',' sailing',' ships',' and',' sealing',
112
+ ' wax,',' of',' cabbages',' and',' kings!']
113
+ end
114
+
115
+ it 'should be able to let whitespace stand alone' do
116
+ string = 'The time has come to talk of many things - of sailing ' +
117
+ 'ships and sealing wax, of cabbages and kings!'
118
+ string.enumerate(:whitespace => :standalone).should ==
119
+ ['The',' ','time',' ','has',' ','come',' ','to',' ','talk',' ','of',
120
+ ' ','many',' ','things',' -',' ','of',' ','sailing',' ','ships',' ','and',' ','sealing',
121
+ ' ','wax,',' ','of',' ','cabbages',' ','and',' ','kings!']
122
+ end
123
+ end
124
+
125
+ describe '(class setter methods)' do
126
+ before :each do
127
+ StringRay::whitespace = nil
128
+ StringRay::delemiters = nil
129
+ end
130
+
131
+ it 'should allow delemiter handling to be set through a class method' do
132
+ StringRay::whitespace = :attach_after
133
+ string = 'The time has come to talk of many things - of sailing ' +
134
+ 'ships and sealing wax, of cabbages and kings!'
135
+ string.enumerate.should ==
136
+ ['The',' time',' has',' come',' to',' talk',' of',
137
+ ' many',' things',' - of',' sailing',' ships',' and',' sealing',
138
+ ' wax,',' of',' cabbages',' and',' kings!']
139
+
140
+ StringRay::whitespace = :standalone
141
+ string = 'The time has come to talk of many things - of sailing ' +
142
+ 'ships and sealing wax, of cabbages and kings!'
143
+ string.enumerate.should ==
144
+ ['The',' ','time',' ','has',' ','come',' ','to',' ','talk',' ','of',
145
+ ' ','many',' ','things',' -',' ','of',' ','sailing',' ','ships',' ','and',' ','sealing',
146
+ ' ','wax,',' ','of',' ','cabbages',' ','and',' ','kings!']
147
+ end
64
148
 
65
- string = "String and Array, sitting in a tree - K-I-S-S-I-N-G!"
66
- array = string.map
67
- array.should == ['String ','and ','Array, ','sitting ','in ','a ','tree - ','K-','I-','S-','S-','I-','N-','G!']
149
+ it 'should allow whitespace handling to be set through a class method' do
150
+ StringRay::whitespace = :attach_after
151
+ string = 'The time has come to talk of many things - of sailing ' +
152
+ 'ships and sealing wax, of cabbages and kings!'
153
+ string.enumerate.should ==
154
+ ['The',' time',' has',' come',' to',' talk',' of',
155
+ ' many',' things',' - of',' sailing',' ships',' and',' sealing',
156
+ ' wax,',' of',' cabbages',' and',' kings!']
157
+
158
+ StringRay::whitespace = :standalone
159
+ string = 'The time has come to talk of many things - of sailing ' +
160
+ 'ships and sealing wax, of cabbages and kings!'
161
+ string.enumerate.should ==
162
+ ['The',' ','time',' ','has',' ','come',' ','to',' ','talk',' ','of',
163
+ ' ','many',' ','things',' -',' ','of',' ','sailing',' ','ships',' ','and',' ','sealing',
164
+ ' ','wax,',' ','of',' ','cabbages',' ','and',' ','kings!']
165
+ end
68
166
  end
69
167
  end
70
168
 
71
169
  # TODO: Figure out a better way to say 'should be_include(Enumerable)'
72
- it 'should also include enumerable' do
73
- String.ancestors.should be_include(Enumerable)
74
- end
170
+ # it 'should also include enumerable' do
171
+ # EString.ancestors.should be_include(Enumerable)
172
+ # end
75
173
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringray
3
3
  version: !ruby/object:Gem::Version
4
- version: "1"
4
+ version: "2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - elliottcable
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-11 00:00:00 -08:00
12
+ date: 2008-08-15 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,11 +30,9 @@ executables: []
30
30
  extensions: []
31
31
 
32
32
  extra_rdoc_files:
33
- - lib/spec/rake/verify_ratio.rb
34
33
  - lib/stringray.rb
35
34
  - README.mkdn
36
35
  files:
37
- - lib/spec/rake/verify_ratio.rb
38
36
  - lib/stringray.rb
39
37
  - Rakefile
40
38
  - README.mkdn
@@ -1,78 +0,0 @@
1
- module Spec
2
- module Rake
3
-
4
- # A task that can verify that the ratio of (lines of spec)
5
- # over (lines of code) doesn't drop below a certain threshold.
6
- # It should be run after running Spec::Rake::SpecTask.
7
- class VerifySpecRatioTask < ::Rake::TaskLib
8
- # Name of the task. Defaults to :verify_spec_ratio
9
- attr_accessor :name
10
-
11
- # Glob pattern to match code files. (default is '**/*.rb')
12
- # Automatically excludes everything matching +spec_pattern+
13
- attr_accessor :pattern
14
-
15
- # Glob pattern to match spec files. (default is 'spec/**/*_spec.rb')
16
- attr_accessor :spec_pattern
17
-
18
- # Whether or not to output details. Defaults to true.
19
- attr_accessor :verbose
20
-
21
- # The threshold value (in decimal value) for ratio. If the
22
- # actual ratio is not above this value, the task will raise an
23
- # exception. The ratio is devised as LoS/LoC, so values above 1
24
- # mean expressive specs, while values below one mean weak specs.
25
- attr_accessor :ratio
26
-
27
- def initialize(name=:verify_spec_ratio)
28
- @name = name
29
- @pattern = '**/*.rb'
30
- @spec_pattern = 'spec/**/*_spec.rb'
31
- @verbose = true
32
- yield self if block_given?
33
- raise "Ratio must be set" if @ratio.nil?
34
- define_task
35
- end
36
-
37
- def define_task
38
- desc "Verify that spec-ratio is at least #{@ratio}%"
39
- task @name do
40
- loc = 0
41
- los = 0
42
-
43
- code_files = Dir[@pattern]
44
- spec_files = Dir[@spec_pattern]
45
-
46
- code_files.each do |code_file|
47
- next if spec_files.include? code_file
48
- code = File.open(code_file)
49
-
50
- code.each_line do |line|
51
- line.gsub! /#(.*)/, '' # Get rid of all comments
52
- line.gsub! /\s/, '' # Get rid of all whitespace
53
- loc += 1 unless line.empty?
54
- end
55
- end
56
-
57
- spec_files.each do |spec_file|
58
- spec = File.open(spec_file)
59
-
60
- spec.each_line do |line|
61
- line.gsub! /#(.*)/, '' # Get rid of all comments
62
- line.gsub! /\s/, '' # Get rid of all whitespace
63
- los += 1 unless line.empty?
64
- end
65
- end
66
-
67
- ratio = (los.to_f / loc.to_f)
68
-
69
- puts "Spec-ratio: #{los}/#{loc} (#{ratio.to_s[0..3]}, expected >=: #{@ratio})" if @verbose
70
- raise "Spec-ratio must be above #{@ratio} but was #{ratio.to_s[0..3]}" if ratio < @ratio
71
- raise "Your spec-ratio file pattern matched no files" if loc == 0
72
- raise "Your spec-ratio specfile pattern matched no files" if los == 0
73
- end
74
- end
75
- end
76
-
77
- end
78
- end