Getting rid of a ton of spec cruft, and starting over. Also making StringRay a class.
[stringray.git] / lib / stringray.rb
blob28ef03d379338ae4e4e888884b1f66ecb557a094
1 require 'stringray/core_ext'
2 require 'stringray/includes'
4 class StringRay < Array
5   Version = 3
6   
7   @@whitespace = nil
8   @@delemiters = nil
9   
10   ##
11   # @see StringRay::Includes#enumerate
12   # @see StringRay::Includes.whitespace=
13   # Controls how +StringRay::Includes#enumerate+ deals with whitespace by default.
14   # 
15   # @param [Symbol] whitespace How to handle whitespace - :attach_before,
16   #   :standalone, or :attach_after
17   def self.whitespace= whitespace
18     @@whitespace = whitespace
19   end
20   
21   def self.whitespace
22     @@whitespace ||= :attach_before
23   end
25   ##
26   # @see StringRay::Includes#enumerate
27   # @see StringRay::Includes.delemiters=
28   # Controls how +StringRay::Includes#enumerate+ deals with delemiters by default.
29   # 
30   # @param [Symbol] delemiters How to handle delemiters - :attach_before,
31   #   :standalone, or :attach_after
32   def self.delemiters= delemiters
33     @@delemiters = delemiters
34   end
35   
36   def self.delemiters
37     @@delemiters ||= :attach_before
38   end
39   
40   # @see StringRay::Word.new
41   def Word word; Word.new word; end
42   
43   ##
44   # A wrapper class for strings that are 'words' in and of themselves,
45   # composed of 'word characters'.
46   class Word < String
47     def inspect
48       "(#{self})"
49     end
50   end
51   
52   # @see StringRay::Whitespace.new
53   def Whitespace whitespace; Whitespace.new whitespace; end
54   
55   ##
56   # A wrapper class for strings that are 'whitespace' composed of 'whitespace
57   # characters'.
58   class Whitespace < String
59     Characters = [" ", "\t", "\n"]
60     
61     def inspect
62       "#{self}"
63     end
64   end
65   
66   # @see StringRay::Delimiter.new
67   def Delimiter delimiter; Delimiter.new delimiter; end
68   
69   ##
70   # A wrapper class for strings that are 'delimiters' composed of 'delimiter
71   # characters'.
72   class Delimiter < String
73     Characters = ['-', ',', '.', '?', '!', ':', ';', '/', '\\', '|']
74     
75     def inspect
76       "<#{self}>"
77     end
78   end
79   
80 end