elliottcable-stringray 2 → 3

Sign up to get free protection for your applications and to get access to all the features.
data/.manifest CHANGED
@@ -1,5 +1,8 @@
1
1
  lib/stringray.rb
2
- Rakefile
3
- README.mkdn
2
+ lib/stringray/core_ext.rb
3
+ lib/stringray/core_ext/kernel.rb
4
+ lib/stringray/core_ext/spec/rake/verify_rcov.rb
4
5
  spec/stringray_spec.rb
6
+ README.markdown
7
+ Rakefile.rb
5
8
  .manifest
data/README.markdown ADDED
@@ -0,0 +1,59 @@
1
+ StringRay
2
+ =========
3
+
4
+ **StringRay** exposes a powerful method to split a `String` into an `Array` of
5
+ words, and further allows you to include `Enumerable`, thus exposing many of the most useful `Array` methods on your `String`s.
6
+
7
+ Links
8
+ -----
9
+
10
+ * [source (GitHub)](http://github.com/elliottcable/stringray "GitHub source repository")
11
+ * [wiki (Google Code)](http://code.google.com/p/stringray/w/list "Google Code wiki")
12
+ * [issues (Google Code)](http://code.google.com/p/stringray/issues "Google Code issues")
13
+ * [Gitorious mirror](http://gitorious.org/projects/stringray "Gitorious source repository")
14
+ * [RubyForge mirror](http://rubyforge.org/projects/stringray/ "RubyForge project")
15
+ * [repo.or.cz mirror](http://repo.or.cz/w/stringray.git "repo.or.cz source repository")
16
+
17
+
18
+ Usage
19
+ -----
20
+
21
+ class String; include StringRay; end
22
+
23
+ "Oi! I'm a string, do something fun with me!".enumerate do |word|
24
+ p word
25
+ end
26
+
27
+ class String; make_enumerable!; end
28
+ "Who, what, when, where, why? The questions these are.".map do |word|
29
+ word << word[0].chr
30
+ end
31
+
32
+ Getting
33
+ -------
34
+
35
+ The authoritative source for this project is available at
36
+ <http://github.com/elliottcable/stringray>. You can clone your own copy with
37
+ the following command:
38
+
39
+ git clone git://github.com/elliottcable/stringray.git
40
+
41
+ If you want to make changes to the codebase, you need to fork your own GitHub
42
+ repository for said changes. Send a pullrequest to [elliottcable](http://github.com/elliottcable "elliottcable on GitHub")
43
+ when you've got something ready for the master branch that you think should be
44
+ merged.
45
+
46
+ Requirements
47
+ ------------
48
+
49
+ To use StringRay, you need... nothing!
50
+
51
+ Contributing
52
+ ------------
53
+
54
+ To develop and contribute to StringRay, you need...
55
+
56
+ * `gem install rake`
57
+ * `gem install rspec`
58
+ * `gem install rcov`
59
+ * `gem install echoe`
@@ -2,48 +2,42 @@
2
2
  require 'stringray'
3
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'
9
+ require 'stringray/core_ext/spec/rake/verify_rcov'
8
10
 
9
11
  begin
10
12
  require 'echoe'
11
13
 
12
- namespace :echoe do
13
- Echoe.new('StringRay', StringRay::VERSION) do |g|
14
- g.name = 'stringray'
14
+ task :package => :'package:package'
15
+ task :install => :'package:install'
16
+ task :manifest => :'package:manifest'
17
+ namespace :package do
18
+ Echoe.new('stringray', StringRay::Version) do |g|
19
+ g.project = 'stringray'
15
20
  g.author = ['elliottcable']
16
21
  g.email = ['StringRay@elliottcable.com']
17
22
  g.summary = 'Combining many of the benefits of Arrays and Strings, StringRay allows you to treat a String as an Array of words in many cases.'
18
23
  g.url = 'http://github.com/elliottcable/stringray'
19
24
  g.dependencies = []
25
+ g.development_dependencies = ['elliottcable-echoe >= 3.0.2', 'rspec', 'rcov', 'yard']
20
26
  g.manifest_name = '.manifest'
21
- g.ignore_pattern = ['.git', 'meta', 'stringray.gemspec']
27
+ g.retain_gemspec = true
28
+ g.rakefile_name = 'Rakefile.rb'
29
+ g.ignore_pattern = /(^\.git$|^\.yardoc$|^meta\/|\.gemspec$)/
22
30
  end
23
31
 
24
32
  desc 'tests packaged files to ensure they are all present'
25
33
  task :verify => :package do
26
34
  # An error message will be displayed if files are missing
27
- if system %(ruby -e "require 'rubygems'; require 'pkg/merb_strokedb-#{StringRay::VERSION}/lib/stringray'")
35
+ if system %(ruby -e "require 'rubygems'; require 'pkg/stringray-#{StringRay::VERSION}/lib/stringray'")
28
36
  puts "\nThe library files are present"
29
37
  end
30
38
  end
31
-
32
- task :copy_gemspec => [:package] do
33
- pkg = Dir['pkg/*'].select {|dir| File.directory? dir}.last
34
- mv File.join(pkg, pkg.gsub(/^pkg\//,'').gsub(/\-\d+$/,'.gemspec')), './'
35
- end
36
-
37
- desc 'builds a gemspec as GitHub wants it'
38
- task :gemspec => [:package, :copy_gemspec, :clobber_package]
39
-
40
- # desc 'Run specs, clean tree, update manifest, run coverage, and install gem!'
41
- desc 'Clean tree, update manifest, and install gem!'
42
- task :magic => [:clean, :manifest, :install]
43
39
  end
44
40
 
45
- task :manifest => [:'echoe:manifest']
46
-
47
41
  rescue LoadError => boom
48
42
  puts "You are missing a dependency required for meta-operations on this gem."
49
43
  puts "#{boom.to_s.capitalize}."
@@ -57,6 +51,7 @@ ensure
57
51
  t.spec_files = Dir['spec/**/*_spec.rb'].sort
58
52
  t.libs = ['lib']
59
53
  t.rcov = true
54
+ t.rcov_opts = ['--exclude-only', '".*"', '--include-file', '^lib']
60
55
  t.rcov_dir = 'meta' / 'coverage'
61
56
  end
62
57
 
@@ -70,8 +65,9 @@ ensure
70
65
  end
71
66
 
72
67
  RCov::VerifyTask.new(:verify) do |t|
73
- t.threshold = 100
68
+ t.threshold = 98.7
74
69
  t.index_html = 'meta' / 'coverage' / 'index.html'
70
+ t.require_exact_threshold = false
75
71
  end
76
72
 
77
73
  task :open do
@@ -79,15 +75,42 @@ ensure
79
75
  end
80
76
  end
81
77
 
78
+ namespace :yard do
79
+ YARD::Rake::YardocTask.new :generate do |t|
80
+ t.files = ['lib/**/*.rb']
81
+ t.options = ['--output-dir', "meta/documentation", '--readme', 'README.markdown']
82
+ end
83
+
84
+ YARD::Rake::YardocTask.new :dot_yardoc do |t|
85
+ t.files = ['lib/**/*.rb']
86
+ t.options = ['--no-output', '--readme', 'README.markdown']
87
+ end
88
+
89
+ task :open do
90
+ system 'open ' + 'meta' / 'documentation' / 'index.html' if PLATFORM['darwin']
91
+ end
92
+ end
93
+
82
94
  namespace :git do
83
95
  task :status do
84
96
  `git status`
85
97
  end
98
+
99
+ task :commit => [:'echoe:manifest', :'yard:dot_yardoc'] do
100
+ `git commit`
101
+ end
102
+ end
103
+
104
+ task :clobber => [:'echoe:clobber_package', :'echoe:clobber_docs', :'echoe:clobber_coverage'] do
105
+ rm_f 'meta'
86
106
  end
87
107
 
88
108
  desc 'Check everything over before commiting'
89
- task :aok => [:'echoe:manifest', :'rcov:run', :'rcov:verify', :'rcov:ratio', :'rcov:open', :'git:status']
109
+ task :aok => [:'yard:generate', :'yard:open',
110
+ :'package:manifest', :'package:package',
111
+ :'rcov:run', :'rcov:verify', :'rcov:open',
112
+ :'git:status']
90
113
 
91
114
  # desc 'Task run during continuous integration' # Invisible
92
- task :cruise => [:'rcov:plain', :'rcov:verify', :'rcov:ratio']
93
- end
115
+ task :ci => [:'yard:generate', :'rcov:plain', :'rcov:verify']
116
+ end
data/lib/stringray.rb CHANGED
@@ -1,120 +1,199 @@
1
+ require 'stringray/core_ext'
2
+
1
3
  module StringRay
2
- VERSION = 2
4
+ Version = 3
3
5
 
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
6
+ @@whitespace = nil
7
+ @@delemiters = nil
8
+
9
+ ##
10
+ # @see #enumerate
11
+ # Controls how +#enumerate+ deals with whitespace.
12
+ #
13
+ # @param [Symbol] whitespace How to handle whitespace - :attach_before,
14
+ # :standalone, or :attach_after
15
+ def self.whitespace= whitespace
16
+ @@whitespace = whitespace
17
+ end
18
+
19
+ def self.whitespace
20
+ @@whitespace ||= :attach_before
21
+ end
22
+
23
+ ##
24
+ # @see #enumerate
25
+ # Controls how +#enumerate+ deals with delemiters.
26
+ #
27
+ # @param [Symbol] delemiters How to handle delemiters - :attach_before,
28
+ # :standalone, or :attach_after
29
+ def self.delemiters= delemiters
30
+ @@delemiters = delemiters
31
+ end
32
+
33
+ def self.delemiters
34
+ @@delemiters ||= :attach_before
35
+ end
36
+
37
+ ##
38
+ # Splits a string into an array of +StringRay+ container objects (+Word+,
39
+ # +Whitespace+, and +Delimiter+).
40
+ #
41
+ # @yield [element] Allows each 'element' of the string to be operated on
42
+ # after it is processed
43
+ # @yieldparam [Word, Whitespace, Delimiter] element The last processed
44
+ # string 'element'
45
+ # @return [Array[Word, Whitespace, Delimiter]] An array of +StringRay+
46
+ # container objects
47
+ # @since 2
48
+ def to_stray
7
49
  ray = []
50
+ new_element = lambda do |element|
51
+ yield ray.last if block_given? unless ray.empty?
52
+ ray << element
53
+ end
8
54
 
9
- self.each_byte do |byte|
10
- char = byte.chr
11
-
55
+ self.scan(/./um) do |char|
12
56
  if Delimiter::Characters.include? char
13
- ray << Delimiter.new(char)
57
+ new_element[Delimiter.new(char)]
14
58
 
15
59
  elsif Whitespace::Characters.include? char
16
60
  if ray.last.is_a? Whitespace
17
61
  ray.last << char
18
62
  else
19
- ray << Whitespace.new(char)
63
+ new_element[Whitespace.new(char)]
20
64
  end
21
65
 
22
66
  else
23
67
  if ray.last.is_a? Word
24
68
  ray.last << char
25
69
  else
26
- ray << Word.new(char)
70
+ new_element[Word.new(char)]
27
71
  end
28
72
 
29
73
  end
30
74
  end
31
75
 
32
- ray
76
+ if block_given?
77
+ yield ray.last
78
+ self
79
+ else
80
+ ray
81
+ end
33
82
  end
34
83
 
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
84
+ ##
85
+ # @see #to_stray
86
+ # @see #whitespace
87
+ # @see #delemiters
88
+ # Enumerates a string, similar to +#to_stray+, but returning an array of
89
+ # plain +String+s instead of container objects.
90
+ #
91
+ # @param [Hash] options A hash of options
92
+ # @yield [word] Allows each word in the string to be operated on after it is
93
+ # processed
94
+ # @yieldparam [String] word The last processed word
95
+ # @return [Array[String]] An array of words
96
+ # @since 1
97
+ def enumerate options = {}, &block
45
98
  mapped = []
46
99
  attach_before_next = []
47
100
 
48
- words.each do |item|
49
- case item
101
+ self.to_stray do |element|
102
+ case element
50
103
  when Delimiter
51
- case opts[:delemiters]
104
+ case options[:delemiters] || StringRay::delemiters
52
105
  when :standalone
53
- mapped << [item]
106
+ mapped << [element]
54
107
  when :attach_after
55
- attach_before_next << item
108
+ attach_before_next << element
56
109
  else
57
110
  if attach_before_next.empty?
58
111
  if mapped.last
59
- mapped.last << item
112
+ mapped.last << element
60
113
  else
61
- attach_before_next << item
114
+ attach_before_next << element
62
115
  end
63
116
  else
64
- attach_before_next << item
117
+ attach_before_next << element
65
118
  end
66
119
  end
67
120
 
68
121
  when Whitespace
69
- case opts[:whitespace]
122
+ case options[:whitespace] || StringRay::whitespace
70
123
  when :standalone
71
- mapped << [item]
124
+ mapped << [element]
72
125
  when :attach_after
73
- attach_before_next << item
126
+ attach_before_next << element
74
127
  else
75
128
  if attach_before_next.empty?
76
129
  if mapped.last
77
- mapped.last << item
130
+ mapped.last << element
78
131
  else
79
- attach_before_next << item
132
+ attach_before_next << element
80
133
  end
81
134
  else
82
- attach_before_next << item
135
+ attach_before_next << element
83
136
  end
84
137
  end
85
138
 
86
139
  when Word
87
140
  if not attach_before_next.empty?
88
- mapped << [attach_before_next, item].flatten
141
+ mapped << [attach_before_next, element].flatten
89
142
  attach_before_next = []
90
143
  else
91
- mapped << [item]
144
+ mapped << [element]
92
145
  end
93
146
 
94
147
  end
95
148
  end
96
- (mapped.last << attach_before_next).flatten! if not attach_before_next.empty?
97
149
 
98
- # Next, we yield each group of (word plus delimiters and whitespace) as a
99
- # normal string to the block
100
- mapped.each do |arr|
101
- yield arr.map{|w|w.to_s}.join
150
+ if not attach_before_next.empty?
151
+ mapped << [Word.new] unless mapped.last
152
+ (mapped.last << attach_before_next).flatten!
153
+ end
154
+
155
+ mapped.map do |arr|
156
+ string = arr.map{|w|w.to_s}.join
157
+ yield string if block_given?
158
+ string
102
159
  end
103
160
  end
104
161
 
162
+ # @deprecated
163
+ alias_method :each_word, :enumerate
164
+
165
+ # @see StringRay::Word.new
166
+ def Word word; Word.new word; end
167
+
168
+ ##
169
+ # A wrapper class for strings that are 'words' in and of themselves,
170
+ # composed of 'word characters'.
105
171
  class Word < String
106
172
  def inspect
107
173
  "(#{self})"
108
174
  end
109
175
  end
110
176
 
177
+ # @see StringRay::Whitespace.new
178
+ def Whitespace whitespace; Whitespace.new whitespace; end
179
+
180
+ ##
181
+ # A wrapper class for strings that are 'whitespace' composed of 'whitespace
182
+ # characters'.
111
183
  class Whitespace < String
112
184
  Characters = [" ", "\t", "\n"]
185
+
113
186
  def inspect
114
187
  "#{self}"
115
188
  end
116
189
  end
117
190
 
191
+ # @see StringRay::Delimiter.new
192
+ def Delimiter delimiter; Delimiter.new delimiter; end
193
+
194
+ ##
195
+ # A wrapper class for strings that are 'delimiters' composed of 'delimiter
196
+ # characters'.
118
197
  class Delimiter < String
119
198
  Characters = ['-', ',', '.', '?', '!', ':', ';', '/', '\\', '|']
120
199
 
@@ -123,14 +202,31 @@ module StringRay
123
202
  end
124
203
  end
125
204
 
126
- # This overrides +String#each+ with +StringRay#each_word+, thus allowing us
127
- # to include +Enumerable+.
128
- def self.included klass
129
- klass.class_eval do
130
- alias_method :each_at, :each
131
- alias_method :each, :each_word
132
-
133
- include Enumerable
205
+ # This is mixed into any class including +StringRay+. It exposes
206
+ # +::make_enumerable!+ to said class.
207
+ module Extendables
208
+
209
+ ##
210
+ # This overrides +String#each+ with +StringRay#enumerate+, thus allowing
211
+ # us to include +Enumerable+. Be careful, this breaks lots of existing
212
+ # code which depends on the old methodology of +String#each+! The
213
+ # overridden +String#each+ functionality will be exposed as
214
+ # +String#each_at+.
215
+ def make_enumerable!
216
+ self.class_eval do
217
+ if RUBY_VERSION <= "1.9"
218
+ Kernel::warn "overriding String#each with StringRay#enumerate; this may break old libaries!"
219
+ alias_method :each_at, :each
220
+ end
221
+ alias_method :each, :enumerate
222
+
223
+ include Enumerable
224
+ end
134
225
  end
226
+
227
+ end
228
+
229
+ def self.included klass
230
+ klass.send :extend, Extendables
135
231
  end
136
- end
232
+ end
@@ -0,0 +1 @@
1
+ require 'stringray/core_ext/kernel'
@@ -0,0 +1,6 @@
1
+ module Kernel
2
+ def self.warn message
3
+ super "#{caller[-1]}: warning: #{message}"
4
+ end
5
+ end
6
+
@@ -0,0 +1,23 @@
1
+ class RCov::VerifyTask
2
+
3
+ # For now, it appears that StringRay's habit of fucking with #each, also
4
+ # screws with RCov generation. RSpec's verification task's fragile code
5
+ # doesn't like that... so let's fix it.
6
+ def define
7
+ desc "Verify that rcov coverage is at least #{threshold}%"
8
+ task @name do
9
+ total_coverage = nil
10
+
11
+ File.open(index_html).each_line do |line|
12
+ if line =~ /<tt\s+class='coverage_total'>\s*(\d+\.\d+)%\s*<\/tt>/
13
+ total_coverage = $1.to_s.to_f
14
+ break
15
+ end
16
+ end
17
+ puts "Coverage: #{total_coverage}% (threshold: #{threshold}%)" if verbose
18
+ raise "Coverage must be at least #{threshold}% but was #{total_coverage}%" if total_coverage < threshold
19
+ raise "Coverage has increased above the threshold of #{threshold}% to #{total_coverage}%. You should update your threshold value." if (total_coverage > threshold) and require_exact_threshold
20
+ end
21
+ end
22
+
23
+ end
@@ -1,108 +1,177 @@
1
1
  ($:.unshift File.expand_path(File.join( File.dirname(__FILE__), '..', 'lib' ))).uniq!
2
2
  require 'stringray'
3
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
+
4
11
  describe 'a String including StringRay' do
5
12
  before :all do
6
- String.send :include, StringRay
13
+ class String
14
+ include StringRay
15
+ end
16
+ end
17
+
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]
35
+ end
7
36
  end
8
37
 
9
38
  describe '#enumerate' do
10
39
  it 'should split a string into an array' do
11
- string = 'The time has come to talk of many things - of sailing ' +
12
- 'ships and sealing wax, of cabbages and kings!'
13
- string.inject([]) {|a, i| a << i }.should ==
14
- ['The ','time ','has ','come ','to ','talk ','of ',
15
- 'many ','things - ','of ','sailing ','ships ','and ','sealing ',
16
- 'wax, ','of ','cabbages ','and ','kings!']
40
+ string = 'This is a string'
41
+ string.enumerate.should ==
42
+ ['This ','is ','a ','string']
17
43
  end
18
44
 
19
45
  it 'should correctly treat commas and lists' do
20
- string = 'I have commas, periods, and other punctuation'
21
- string.inject([]) {|a, i| a << i }.should ==
22
- ['I ','have ','commas, ','periods, ','and ','other ','punctuation']
46
+ string = 'Commas, commas, commas'
47
+ string.enumerate.should ==
48
+ ['Commas, ','commas, ','commas']
23
49
  end
24
50
 
25
- it 'should correctly treat periods and end-of-sentance demarcators' do
26
- string = 'Periods. Cool right? Yah!'
27
- string.inject([]) {|a, i| a << i }.should ==
28
- ['Periods. ','Cool ','right? ','Yah!']
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!']
29
55
  end
30
56
 
31
57
  it 'should correctly treat dahses' do
32
- string = 'I have - uh - dashes!'
33
- string.inject([]) {|a, i| a << i }.should ==
34
- ['I ','have - ','uh - ','dashes!']
58
+ string = 'I have - uh - dashes'
59
+ string.enumerate.should ==
60
+ ['I ','have - ','uh - ','dashes']
35
61
  end
36
62
 
37
63
  it 'should correctly treat ellipses' do
38
- string = 'Where are we... going?'
39
- string.inject([]) {|a, i| a << i }.should ==
40
- ['Where ','are ','we... ','going?']
64
+ string = 'Where... are we... going'
65
+ string.enumerate.should ==
66
+ ['Where... ','are ','we... ','going']
41
67
  end
42
68
 
43
69
  it 'should correctly treat a delimated word' do
44
- string = 'String and Array, sitting in a tree - K-I-S-S-I-N-G!'
45
- string.inject([]) {|a, i| a << i }.should ==
46
- ['String ','and ','Array, ','sitting ','in ','a ','tree - ','K-','I-','S-','S-','I-','N-','G!']
70
+ string = 'Pneumono-ultra-microscopic-silico-volcano-koniosis'
71
+ string.enumerate.should ==
72
+ ['Pneumono-','ultra-','microscopic-','silico-','volcano-','koniosis']
47
73
  end
48
74
 
49
75
  it 'should correctly treat inline line returns' do
50
- string = "This has\na line return!"
51
- string.inject([]) {|a, i| a << i }.should ==
52
- ["This ","has\n","a ","line ","return!"]
76
+ string = "Line\nreturns\nyay"
77
+ string.enumerate.should ==
78
+ ["Line\n","returns\n","yay"]
53
79
  end
54
80
 
55
81
  it 'should correctly treat prefacing line returns and whitespace' do
56
- string = "\n Now it starts!\n\n"
57
- string.inject([]) {|a, i| a << i }.should ==
58
- ["\n Now ","it ","starts!\n\n"]
59
- end
60
- end
61
-
62
- describe '#each_word' do
63
- it 'should be able to attach delimeters to the beginning of the next word' do
64
- string = 'The time has come to talk of many things - of sailing ' +
65
- 'ships and sealing wax, of cabbages and kings!'
66
- array = []
67
- string.each(:delemiters => :attach_after) {|i| array << i }
68
- array.should == ['The ','time ','has ','come ','to ','talk ','of ',
69
- 'many ','things ','- of ','sailing ','ships ','and ','sealing ',
70
- 'wax',', of ','cabbages ','and ','kings!']
82
+ string = "\n\t # Code\n\n"
83
+ string.enumerate.should ==
84
+ ["\n\t # ","Code\n\n"]
71
85
  end
72
86
 
73
- it 'should be able to let delimeters stand alone' do
74
- string = 'The time has come to talk of many things - of sailing ' +
75
- 'ships and sealing wax, of cabbages and kings!'
76
- array = []
77
- string.each(:delemiters => :standalone) {|i| array << i }
78
- array.should == ['The ','time ','has ','come ','to ','talk ','of ',
79
- 'many ','things ','- ', 'of ','sailing ','ships ','and ','sealing ',
80
- 'wax',', ','of ','cabbages ','and ','kings','!']
81
- end
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
82
105
 
83
- it 'should be able to attach whitespace to the beginning of the next word' do
84
- string = 'The time has come to talk of many things - of sailing ' +
85
- 'ships and sealing wax, of cabbages and kings!'
86
- array = []
87
- string.each(:whitespace => :attach_after) {|i| array << i }
88
- array.should == ['The',' time',' has',' come',' to',' talk',' of',
89
- ' many',' things',' - of',' sailing',' ships',' and',' sealing',
90
- ' wax,',' of',' cabbages',' and',' kings!']
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
91
123
  end
92
124
 
93
- it 'should be able to let whitespace stand alone' do
94
- string = 'The time has come to talk of many things - of sailing ' +
95
- 'ships and sealing wax, of cabbages and kings!'
96
- array = []
97
- string.each(:whitespace => :standalone) {|i| array << i }
98
- array.should == ['The',' ','time',' ','has',' ','come',' ','to',' ','talk',' ','of',
99
- ' ','many',' ','things',' -',' ','of',' ','sailing',' ','ships',' ','and',' ','sealing',
100
- ' ','wax,',' ','of',' ','cabbages',' ','and',' ','kings!']
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
148
+
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
101
166
  end
102
167
  end
103
168
 
104
- # TODO: Figure out a better way to say 'should be_include(Enumerable)'
105
- it 'should also include enumerable' do
106
- String.ancestors.should be_include(Enumerable)
169
+ it 'should be capable of making String enumerable' do
170
+ class ExtendedString < String
171
+ include StringRay
172
+ make_enumerable!
173
+ end
174
+
175
+ ExtendedString.ancestors.should be_include(Enumerable)
107
176
  end
108
177
  end
data/stringray.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{stringray}
5
+ s.version = "3"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["elliottcable"]
9
+ s.date = %q{2009-06-11}
10
+ s.description = %q{Combining many of the benefits of Arrays and Strings, StringRay allows you to treat a String as an Array of words in many cases.}
11
+ s.email = ["StringRay@elliottcable.com"]
12
+ s.extra_rdoc_files = ["lib/stringray.rb", "lib/stringray/core_ext.rb", "lib/stringray/core_ext/kernel.rb", "lib/stringray/core_ext/spec/rake/verify_rcov.rb", "README.markdown"]
13
+ s.files = ["lib/stringray.rb", "lib/stringray/core_ext.rb", "lib/stringray/core_ext/kernel.rb", "lib/stringray/core_ext/spec/rake/verify_rcov.rb", "spec/stringray_spec.rb", "README.markdown", "Rakefile.rb", ".manifest", "stringray.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/elliottcable/stringray}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Stringray", "--main", "README.markdown"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{stringray}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Combining many of the benefits of Arrays and Strings, StringRay allows you to treat a String as an Array of words in many cases.}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<elliottcable-echoe>, [">= 0", "= 3.0.2"])
28
+ s.add_development_dependency(%q<rspec>, [">= 0"])
29
+ s.add_development_dependency(%q<rcov>, [">= 0"])
30
+ s.add_development_dependency(%q<yard>, [">= 0"])
31
+ else
32
+ s.add_dependency(%q<elliottcable-echoe>, [">= 0", "= 3.0.2"])
33
+ s.add_dependency(%q<rspec>, [">= 0"])
34
+ s.add_dependency(%q<rcov>, [">= 0"])
35
+ s.add_dependency(%q<yard>, [">= 0"])
36
+ end
37
+ else
38
+ s.add_dependency(%q<elliottcable-echoe>, [">= 0", "= 3.0.2"])
39
+ s.add_dependency(%q<rspec>, [">= 0"])
40
+ s.add_dependency(%q<rcov>, [">= 0"])
41
+ s.add_dependency(%q<yard>, [">= 0"])
42
+ end
43
+ end
metadata CHANGED
@@ -1,18 +1,52 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elliottcable-stringray
3
3
  version: !ruby/object:Gem::Version
4
- version: "2"
4
+ version: "3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - elliottcable
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- date: 2008-08-12 01:00:00 -07:00
10
+ cert_chain: []
11
+
12
+ date: 2009-06-11 00:00:00 -07:00
12
13
  default_executable:
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
- name: echoe
16
+ name: elliottcable-echoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ - - "="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.2
27
+ version:
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ type: :development
31
+ version_requirement:
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: "0"
37
+ version:
38
+ - !ruby/object:Gem::Dependency
39
+ name: rcov
40
+ type: :development
41
+ version_requirement:
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ - !ruby/object:Gem::Dependency
49
+ name: yard
16
50
  type: :development
17
51
  version_requirement:
18
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,14 +64,20 @@ extensions: []
30
64
 
31
65
  extra_rdoc_files:
32
66
  - lib/stringray.rb
33
- - README.mkdn
67
+ - lib/stringray/core_ext.rb
68
+ - lib/stringray/core_ext/kernel.rb
69
+ - lib/stringray/core_ext/spec/rake/verify_rcov.rb
70
+ - README.markdown
34
71
  files:
35
72
  - lib/stringray.rb
36
- - Rakefile
37
- - README.mkdn
73
+ - lib/stringray/core_ext.rb
74
+ - lib/stringray/core_ext/kernel.rb
75
+ - lib/stringray/core_ext/spec/rake/verify_rcov.rb
38
76
  - spec/stringray_spec.rb
77
+ - README.markdown
78
+ - Rakefile.rb
39
79
  - .manifest
40
- - StringRay.gemspec
80
+ - stringray.gemspec
41
81
  has_rdoc: true
42
82
  homepage: http://github.com/elliottcable/stringray
43
83
  post_install_message:
@@ -45,9 +85,9 @@ rdoc_options:
45
85
  - --line-numbers
46
86
  - --inline-source
47
87
  - --title
48
- - StringRay
88
+ - Stringray
49
89
  - --main
50
- - README.mkdn
90
+ - README.markdown
51
91
  require_paths:
52
92
  - lib
53
93
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -58,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
98
  version:
59
99
  required_rubygems_version: !ruby/object:Gem::Requirement
60
100
  requirements:
61
- - - "="
101
+ - - ">="
62
102
  - !ruby/object:Gem::Version
63
103
  version: "1.2"
64
104
  version:
data/README.mkdn DELETED
@@ -1,41 +0,0 @@
1
- StringRay
2
- =========
3
-
4
- **StringRay** exposes a powerful method to split a `String` into an `Array` of words,
5
- and further allows you to include `Enumerable`, thus exposing many of the
6
- most useful `Array` methods on your `String`s.
7
-
8
- Usage
9
- -----
10
-
11
- class String; include StringRay; end
12
-
13
- "Oi! I'm a string, do something fun with me!".each do |word|
14
- p word
15
- end
16
-
17
- Getting
18
- -------
19
-
20
- The authoritative source for this project is available at
21
- <http://github.com/elliottcable/stringray>. You can clone your own copy with the
22
- following command:
23
-
24
- git clone git://github.com/elliottcable/stringray.git
25
-
26
- If you want to make changes to the codebase, you need to fork your own GitHub
27
- repository for said changes. Send a pullrequest to [elliottcable](http://github.com/elliottcable "elliottcable on GitHub")
28
- when you've got something ready for the master branch that you think should be
29
- merged.
30
-
31
- Requirements
32
- ------------
33
-
34
- To run git-blog, you need... nothing!
35
-
36
- To develop and contribute to git-blog, you also need:
37
-
38
- * `gem install rake`
39
- * `gem install rspec`
40
- * `gem install rcov`
41
- * `gem install echoe`