re 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. data/README.rdoc +4 -4
  2. data/Rakefile +7 -3
  3. data/TAGS +140 -0
  4. data/lib/re.rb +26 -11
  5. data/test/re_test.rb +34 -0
  6. metadata +13 -5
@@ -34,13 +34,13 @@ easier to independently verify. As an additional bonus, the capture
34
34
  groups can be retrieved by name:
35
35
 
36
36
  result = date.match("2009-01-23")
37
- result.data(:year) # => "2009"
38
- result.data(:month) # => "01"
39
- result.data(:day) # => "23"
37
+ result[:year] # => "2009"
38
+ result[:month] # => "01"
39
+ result[:day] # => "23"
40
40
 
41
41
  == Version
42
42
 
43
- This document describes Re version 0.0.5.
43
+ This document describes Re version 0.0.6.
44
44
 
45
45
  == Usage
46
46
 
data/Rakefile CHANGED
@@ -20,8 +20,8 @@ namespace "release" do
20
20
  :check_non_beta,
21
21
  :check_all_committed,
22
22
  :tag_version,
23
- :gem,
24
- "publish:rdoc"
23
+ "publish:rdoc",
24
+ "publish:gem",
25
25
  ]
26
26
 
27
27
  task :check_all_committed do
@@ -35,7 +35,11 @@ namespace "release" do
35
35
  sh "git commit -m 'bumped to version #{Re::VERSION}'"
36
36
  end
37
37
 
38
- task :not_already_tagged
38
+ task :not_already_tagged do
39
+ if `git tag -l re-#{Re::VERSION}` != ""
40
+ fail "Already tagged with re-#{Re::VERSION}"
41
+ end
42
+ end
39
43
 
40
44
  task :tag_version => :not_already_tagged do
41
45
  sh "git tag re-#{Re::VERSION}"
data/TAGS ADDED
@@ -0,0 +1,140 @@
1
+
2
+ bench/date_bench.rb,64
3
+ def date_rexpdate_rexp7,48
4
+ def date_regexpdate_regexp22,621
5
+
6
+ lib/re.rb,2303
7
+ module ReRe161,5658
8
+ module VersionVersion163,5671
9
+ class ResultResult175,5934
10
+ def initialize(match_data, rexp)initialize178,6041
11
+ def full_matchfull_match184,6182
12
+ def [](name)[]189,6284
13
+ def name_mapname_map197,6440
14
+ class RexpRexp215,6926
15
+ def initialize(string, level, keys, options=0)initialize221,7163
16
+ def match(string)match231,7429
17
+ def regexpregexp238,7616
18
+ def greedy?greedy?244,7791
19
+ def name_mapname_map250,7969
20
+ def +(other)+260,8196
21
+ def |(other)|267,8431
22
+ def optionaloptional274,8652
23
+ def non_greedynon_greedy283,9059
24
+ def manymany290,9200
25
+ def one_or_moreone_or_more295,9383
26
+ def repeat(min, max=nil)repeat302,9680
27
+ def at_least(min)at_least311,10021
28
+ def at_most(max)at_most316,10219
29
+ def allall322,10430
30
+ def almost_allalmost_all328,10611
31
+ def bolbol333,10735
32
+ def eoleol338,10902
33
+ def beginbegin343,11075
34
+ def endend349,11298
35
+ def very_endvery_end355,11521
36
+ def lineline360,11686
37
+ def groupgroup368,11968
38
+ def capture(name)capture375,12235
39
+ def multilinemultiline380,12405
40
+ def multiline?multiline?387,12675
41
+ def ignore_caseignore_case392,12809
42
+ def ignore_case?ignore_case?400,13153
43
+ def to_sto_s405,13290
44
+ def apply_greedy(op)apply_greedy413,13487
45
+ def parenthesized_encoding(new_level)parenthesized_encoding422,13792
46
+ def encodingencoding432,14053
47
+ def encode_options # :nodoc:encode_options441,14264
48
+ def self.literal(chars)literal451,14652
49
+ def self.raw(re_string) # :no-doc:raw459,14980
50
+ def self.escape_any(chars) # :nodoc:escape_any464,15126
51
+ def re(exp=nil)re477,15501
52
+ module ConstructionMethodsConstructionMethods487,15899
53
+ def nullnull495,16061
54
+ def any(*chars)any525,17136
55
+ def none(*chars)none554,18073
56
+ def char_class(chars)char_class558,18164
57
+ def spacespace576,18550
58
+ def spacesspaces585,18758
59
+ def nonspacenonspace594,18961
60
+ def nonspacesnonspaces603,19182
61
+ def word_charword_char612,19391
62
+ def wordword621,19597
63
+ def breakbreak630,19841
64
+ def digitdigit639,20023
65
+ def digitsdigits648,20212
66
+ def hex_digithex_digit657,20415
67
+ def hex_digitshex_digits666,20637
68
+
69
+ test/re_test.rb,3835
70
+ class ReTest < Test::Unit::TestCaseReTest11,207
71
+ def test_module_access_to_re_functiontest_module_access_to_re_function14,257
72
+ def test_strings_matchtest_strings_match19,347
73
+ def test_not_matchtest_not_match24,433
74
+ def test_special_characters_matchtest_special_characters_match28,487
75
+ def test_concatenationtest_concatenation33,572
76
+ def test_nulltest_null39,674
77
+ def test_alterationtest_alteration44,754
78
+ def test_manytest_many51,871
79
+ def test_greedy_manytest_greedy_many59,1001
80
+ def test_non_greedy_manytest_non_greedy_many66,1156
81
+ def test_one_or_moretest_one_or_more73,1324
82
+ def test_greedy_one_or_moretest_greedy_one_or_more80,1449
83
+ def test_non_greedy_one_or_moretest_non_greedy_one_or_more87,1623
84
+ def test_repeat_fixed_numbertest_repeat_fixed_number94,1810
85
+ def test_repeat_rangetest_repeat_range101,1944
86
+ def test_repeat_greedytest_repeat_greedy110,2118
87
+ def test_repeat_non_greedytest_repeat_non_greedy116,2248
88
+ def test_at_leasttest_at_least122,2391
89
+ def test_at_least_greedytest_at_least_greedy129,2530
90
+ def test_at_least_non_greedytest_at_least_non_greedy135,2661
91
+ def test_at_mosttest_at_most141,2804
92
+ def test_at_most_greedytest_at_most_greedy151,2992
93
+ def test_at_most_non_greedytest_at_most_non_greedy157,3122
94
+ def test_optionaltest_optional169,3469
95
+ def test_any_with_no_argumentstest_any_with_no_arguments176,3585
96
+ def test_no_optionstest_no_options187,3788
97
+ def test_any_with_multilinetest_any_with_multiline196,3973
98
+ def test_ignore_casetest_ignore_case202,4086
99
+ def test_partial_ignore_casetest_partial_ignore_case208,4190
100
+ def test_options_no_not_modify_existing_rexpstest_options_no_not_modify_existing_rexps215,4337
101
+ def test_any_with_a_character_listtest_any_with_a_character_list223,4477
102
+ def test_any_with_special_charstest_any_with_special_chars231,4627
103
+ def test_any_with_a_range_of_charstest_any_with_a_range_of_chars243,4860
104
+ def test_any_with_a_range_and_mix_of_charstest_any_with_a_range_and_mix_of_chars248,4980
105
+ def test_none_with_a_character_listtest_none_with_a_character_list253,5093
106
+ def test_none_with_special_charstest_none_with_special_chars261,5245
107
+ def test_none_with_a_range_of_charstest_none_with_a_range_of_chars273,5480
108
+ def test_none_with_a_range_and_mix_of_charstest_none_with_a_range_and_mix_of_chars281,5644
109
+ def test_alltest_all289,5820
110
+ def test_almost_alltest_almost_all297,5948
111
+ def test_all_across_linestest_all_across_lines305,6090
112
+ def test_linetest_line311,6195
113
+ def test_boltest_bol319,6335
114
+ def test_eoltest_eol327,6469
115
+ def test_begintest_begin335,6609
116
+ def test_begin2test_begin2344,6770
117
+ def test_endtest_end353,6937
118
+ def test_end2test_end2363,7125
119
+ def test_very_endtest_very_end373,7319
120
+ def test_hex_digittest_hex_digit383,7517
121
+ def test_hex_digitstest_hex_digits392,7671
122
+ def test_digittest_digit398,7787
123
+ def test_digitstest_digits407,7935
124
+ def test_breaktest_break413,8043
125
+ def test_nonspacetest_nonspace419,8180
126
+ def test_nonspacestest_nonspaces430,8374
127
+ def test_spacetest_space438,8531
128
+ def test_spacestest_spaces449,8742
129
+ def test_word_chartest_word_char458,8897
130
+ def test_wordtest_word467,9052
131
+ def test_single_capturetest_single_capture475,9217
132
+ def test_multiple_capturetest_multiple_capture482,9387
133
+ def test_precedence_concatentaion_vs_alterationtest_precedence_concatentaion_vs_alteration495,9883
134
+ def test_precendence_of_eoltest_precendence_of_eol502,10046
135
+ def test_exampletest_example506,10110
136
+ def test_date_parsertest_date_parser516,10450
137
+ def test_date_capturetest_date_capture537,11158
138
+ def test_name_map_returns_map_of_keywordstest_name_map_returns_map_of_keywords545,11363
139
+ def date_redate_re556,11648
140
+ def date_redate_re562,11725
data/lib/re.rb CHANGED
@@ -35,9 +35,9 @@
35
35
  # groups can be retrieved by name:
36
36
  #
37
37
  # result = date.match("2009-01-23")
38
- # result.data(:year) # => "2009"
39
- # result.data(:month) # => "01"
40
- # result.data(:day) # => "23"
38
+ # result[:year] # => "2009"
39
+ # result[:month] # => "01"
40
+ # result[:day] # => "23"
41
41
  #
42
42
  # == Usage
43
43
  #
@@ -164,8 +164,7 @@ module Re
164
164
  NUMBERS = [
165
165
  MAJOR = 0,
166
166
  MINOR = 0,
167
- BUILD = 5,
168
- BETA = nil,
167
+ BUILD = 6,
169
168
  ].compact
170
169
  end
171
170
  VERSION = Version::NUMBERS.join('.')
@@ -173,6 +172,8 @@ module Re
173
172
  # Re::Result captures the result of a match and allows lookup of the
174
173
  # captured groups by name.
175
174
  class Result
175
+ include Enumerable
176
+
176
177
  # Create a Re result object with the match data and the original
177
178
  # Re::Rexp object.
178
179
  def initialize(match_data, rexp)
@@ -191,6 +192,20 @@ module Re
191
192
  index ? @match_data[index] : nil
192
193
  end
193
194
 
195
+ def keys
196
+ name_map.keys.sort_by { |k| name_map[k] }
197
+ end
198
+
199
+ def values
200
+ keys.map { |k| self[k] }
201
+ end
202
+
203
+ def each
204
+ keys.each do |k|
205
+ yield([k, self[k]])
206
+ end
207
+ end
208
+
194
209
  private
195
210
 
196
211
  # Lazy eval map of names to capture indices.
@@ -516,11 +531,11 @@ module Re
516
531
  # Examples:
517
532
  #
518
533
  # re.any -- matches any character
519
- # re.any("aieouy") -- matches vowels
520
- # re.any("0-9") -- matches digits
521
- # re.any("A-Z", "a-z", "0-9") -- matches alphanumerics
522
- # re.any("A-Z", "a-z", "0-9", "_") -- matches alphanumerics
523
- # plus an underscore
534
+ # re.any("aieouy") -- matches any vowel
535
+ # re.any("0-9") -- matches any digit
536
+ # re.any("A-Z", "a-z", "0-9") -- matches any alphanumeric character
537
+ # re.any("A-Z", "a-z", "0-9", "_") -- matches any alphanumeric character
538
+ # or an underscore
524
539
  #
525
540
  def any(*chars)
526
541
  if chars.empty?
@@ -637,7 +652,7 @@ module Re
637
652
  # Regular expression that matches a single digit. (equivalent to
638
653
  # /\d/)
639
654
  def digit
640
- @digit ||= any("0-9")
655
+ @digit ||= Rexp.raw("\\d")
641
656
  end
642
657
 
643
658
  # :call-seq:
@@ -8,6 +8,40 @@
8
8
  require 'test/unit'
9
9
  require 're'
10
10
 
11
+ class ReResultTeset < Test::Unit::TestCase
12
+ include Re
13
+ extend Re
14
+
15
+ PATTERN = re.any("a-z").one_or_more.capture(:alphas) + re.digits.capture(:digits)
16
+
17
+ def setup
18
+ @result = PATTERN.match("<abc123>")
19
+ end
20
+
21
+ def test_result_has_full_match
22
+ assert_equal "abc123", @result.full_match
23
+ end
24
+
25
+ def test_result_has_individual_matches
26
+ assert_equal "abc", @result[:alphas]
27
+ assert_equal "123", @result[:digits]
28
+ end
29
+
30
+ def test_result_has_capture_keys
31
+ assert_equal [:alphas, :digits], @result.keys
32
+ end
33
+
34
+ def test_result_has_capture_values
35
+ assert_equal ["abc", "123"], @result.values
36
+ end
37
+
38
+ def test_result_can_be_enumerated
39
+ assert_equal [[:alphas, "abc"], [:digits, "123"]], @result.map {
40
+ |item| item
41
+ }
42
+ end
43
+ end
44
+
11
45
  class ReTest < Test::Unit::TestCase
12
46
  include Re
13
47
 
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: re
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 6
9
+ version: 0.0.6
5
10
  platform: ruby
6
11
  authors:
7
12
  - Jim Weirich
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-12-31 00:00:00 -05:00
17
+ date: 2010-05-06 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -25,6 +30,7 @@ files:
25
30
  - MIT-LICENSE
26
31
  - Rakefile
27
32
  - README.rdoc
33
+ - TAGS
28
34
  - lib/re.rb
29
35
  - test/re_test.rb
30
36
  has_rdoc: true
@@ -45,18 +51,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
51
  requirements:
46
52
  - - ">="
47
53
  - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
48
56
  version: "0"
49
- version:
50
57
  required_rubygems_version: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - ">="
53
60
  - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
54
63
  version: "0"
55
- version:
56
64
  requirements: []
57
65
 
58
66
  rubyforge_project: re-lib
59
- rubygems_version: 1.3.5
67
+ rubygems_version: 1.3.6
60
68
  signing_key:
61
69
  specification_version: 3
62
70
  summary: Construct Ruby Regular Expressions