range_extd 0.3.0 → 0.4.0
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.
- checksums.yaml +4 -4
- data/ChangeLog +7 -1
- data/News +4 -0
- data/README.en.rdoc +2 -0
- data/README.ja.rdoc +4 -0
- data/lib/range_extd/range_extd.rb +125 -0
- data/range_extd.gemspec +2 -2
- data/test/test_range_extd.rb +99 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ae4357a6b6bbdeef30dcb66b575388a2dd3618a
|
4
|
+
data.tar.gz: fc6c6e5b28f72d7fc6fc5cb1773c06eeafc7bbed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bee19fa323a3f55f3cd18dd95f5045296ef673e85a0e9a7b3ce339e5c0c0cf80e3015b20d3f9dac194158e644c7a4dd1228399fd1c2d96296186ff399d58bb20
|
7
|
+
data.tar.gz: e315e80026704a8a062b0122c408cbeb120e1d623370d4f611df7f92e6544876014415e75a263925fa1b39cbd949c69e59e53f10520f01fbf398c955c69d7b9c
|
data/ChangeLog
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
-----
|
2
|
+
(Version: 0.4.0)
|
3
|
+
2014-05-10 Masa Saskano
|
4
|
+
* Added Range#equiv? and RangeExtd#equiv? methods.
|
5
|
+
|
1
6
|
-----
|
2
7
|
(Version: 0.3.0)
|
3
|
-
2014-05-02 Masa
|
8
|
+
2014-05-02 Masa Sakano
|
9
|
+
|
4
10
|
* Added a String expression form of RangeExtd.new and RangeExtd.valid?(), modifying RangeExtd._get_init_args().
|
5
11
|
|
6
12
|
-----
|
data/News
CHANGED
data/README.en.rdoc
CHANGED
@@ -147,6 +147,7 @@ For more detail and examples, see {RangeExtd.new}.
|
|
147
147
|
RangeExtd(?a, ?e, true, true).empty? # => false
|
148
148
|
RangeExtd::NONE.is_none? # => true
|
149
149
|
RangeExtd::ALL.is_all? # => true
|
150
|
+
(3...7).equiv?(3..6) # => true
|
150
151
|
|
151
152
|
All the methods that are in the built-in Range can be used.
|
152
153
|
|
@@ -216,6 +217,7 @@ See the document of each method for detail (some are defined only in
|
|
216
217
|
* <tt>null?</tt>
|
217
218
|
* <tt>is_none?</tt>
|
218
219
|
* <tt>is_all?</tt>
|
220
|
+
* <tt>equiv?</tt>
|
219
221
|
|
220
222
|
There are three class methods, the first of which is equivalent
|
221
223
|
to the instance method <tt>valid?</tt>:
|
data/README.ja.rdoc
CHANGED
@@ -147,6 +147,7 @@ For more detail and examples, see {RangeExtd.new}.
|
|
147
147
|
RangeExtd(?a, ?e, true, true).empty? # => false
|
148
148
|
RangeExtd::NONE.is_none? # => true
|
149
149
|
RangeExtd::ALL.is_all? # => true
|
150
|
+
(3...7).equiv?(3..6) # => true
|
150
151
|
|
151
152
|
All the methods that are in the built-in Range can be used.
|
152
153
|
|
@@ -216,6 +217,7 @@ See the document of each method for detail (some are defined only in
|
|
216
217
|
* <tt>null?</tt>
|
217
218
|
* <tt>is_none?</tt>
|
218
219
|
* <tt>is_all?</tt>
|
220
|
+
* <tt>equiv?</tt>
|
219
221
|
|
220
222
|
There are three class methods, the first of which is equivalent
|
221
223
|
to the instance method <tt>valid?</tt>:
|
@@ -481,6 +483,7 @@ Versions:: The versions of this package follow Semantic Versioning (2.0.0) http:
|
|
481
483
|
RangeExtd(?a, ?e, true, true).empty? # => false
|
482
484
|
RangeExtd::NONE.is_none? # => true
|
483
485
|
RangeExtd::ALL.is_all? # => true
|
486
|
+
(3...7).equiv?(3..6) # => true
|
484
487
|
|
485
488
|
組込Rangeに含まれる全てのメソッドが使用可能です。
|
486
489
|
|
@@ -547,6 +550,7 @@ RangeExtd のインスタンスは、 Rangeと同じくイミュータブルで
|
|
547
550
|
* <tt>null?</tt>
|
548
551
|
* <tt>is_none?</tt>
|
549
552
|
* <tt>is_all?</tt>
|
553
|
+
* <tt>equiv?</tt>
|
550
554
|
|
551
555
|
クラスメソッドが三つあります。一番上のものは、
|
552
556
|
インスタンスメソッドの <tt>valid?</tt> に等価です。
|
@@ -326,6 +326,77 @@ class RangeExtd < Range
|
|
326
326
|
alias :member? :===
|
327
327
|
|
328
328
|
|
329
|
+
# Return true if self and the other are equivalent; if [#to_a] is defined, it is similar to
|
330
|
+
# (self.to_a == other.to_a)
|
331
|
+
# (though the ends are checked more rigorously), and if not, equivalent to
|
332
|
+
# (self == other)
|
333
|
+
#
|
334
|
+
# @example
|
335
|
+
# RangeExtd(2...7,true).equiv?(3..6) # => true
|
336
|
+
# RangeExtd(2...7,true).equiv?(3..6.0) # => false
|
337
|
+
# RangeExtd(2...7,true).equiv?(3.0..6.0) # => false
|
338
|
+
# RangeExtd(2...7,true).equiv?(3..6.5) # => false
|
339
|
+
# RangeExtd(2...7,true).equiv?(RangeExtd(2.0...7.0,true)) # => true
|
340
|
+
# RangeExtd(2...7,true).equiv?(3...7.0) # => true
|
341
|
+
#
|
342
|
+
# @param other [Range, RangeExtd]
|
343
|
+
def equiv?(other)
|
344
|
+
# This routine is very similar to Range#equiv? except
|
345
|
+
# exclude_begin? in this object is always defined, hence
|
346
|
+
# a more thorough check is needed.
|
347
|
+
|
348
|
+
t_or_f = (defined?(self.begin.succ) && defined?(other.begin.succ) && defined?(other.end) && defined?(other.exclude_end?))
|
349
|
+
if ! t_or_f
|
350
|
+
return(self == other) # succ() for begin is not defined.
|
351
|
+
else
|
352
|
+
# Checking the begins.
|
353
|
+
if defined?(other.exclude_begin?)
|
354
|
+
other_excl_beg = other.exclude_begin?
|
355
|
+
else
|
356
|
+
other_excl_beg = false
|
357
|
+
end
|
358
|
+
|
359
|
+
if (self.begin == other.begin)
|
360
|
+
if (exclude_begin? ^! other_excl_beg)
|
361
|
+
# Pass
|
362
|
+
else
|
363
|
+
return false
|
364
|
+
end
|
365
|
+
else
|
366
|
+
if (exclude_begin? ^! other_excl_beg)
|
367
|
+
return false
|
368
|
+
elsif (exclude_begin? && (self.begin.succ == other.begin)) ||
|
369
|
+
(other_excl_beg && (self.begin == other.begin.succ))
|
370
|
+
# Pass
|
371
|
+
else
|
372
|
+
return false
|
373
|
+
end
|
374
|
+
end # if (self.begin == other.begin) # else
|
375
|
+
|
376
|
+
# Now, the begins agreed. Checking the ends.
|
377
|
+
if (self.end == other.end)
|
378
|
+
if (exclude_end? ^! other.exclude_end?)
|
379
|
+
return true
|
380
|
+
else
|
381
|
+
return false
|
382
|
+
end
|
383
|
+
else # if (self.end == other.end)
|
384
|
+
if (exclude_end? ^! other.exclude_end?)
|
385
|
+
return false
|
386
|
+
# elsif defined?(other.last) && (self.last(1) == other.last(1)) # Invalid for Ruby 1.8 or earlier # This is not good - eg., in this case, (1..5.5).equiv?(1..5.4) would return true.
|
387
|
+
|
388
|
+
# return true
|
389
|
+
elsif ( exclude_end? && defined?(other.end.succ) && (self.end == other.end.succ)) ||
|
390
|
+
(other.exclude_end? && defined?( self.end.succ) && (self.end.succ == other.end))
|
391
|
+
return true
|
392
|
+
else
|
393
|
+
return false
|
394
|
+
end
|
395
|
+
end # if (self.end == other.end)
|
396
|
+
end # if ! t_or_f
|
397
|
+
end # def equiv?(other)
|
398
|
+
|
399
|
+
|
329
400
|
# @return [Object]
|
330
401
|
def begin()
|
331
402
|
@rangepart.begin()
|
@@ -1345,6 +1416,60 @@ class Range
|
|
1345
1416
|
false
|
1346
1417
|
end
|
1347
1418
|
|
1419
|
+
|
1420
|
+
# Return true if self and the other are equivalent; if [#to_a] is defined, it is similar to
|
1421
|
+
# (self.to_a == other.to_a)
|
1422
|
+
# (though the ends are checked more rigorously), and if not, equivalent to
|
1423
|
+
# (self == other)
|
1424
|
+
#
|
1425
|
+
# @example
|
1426
|
+
# (3...7).equiv?(3..6) # => true
|
1427
|
+
# (3...7).equiv?(3..6.0) # => false
|
1428
|
+
# (3...7).equiv?(3.0..6.0) # => false
|
1429
|
+
# (3...7).equiv?(3..6.5) # => false
|
1430
|
+
# (3...7).equiv?(3.0...7.0) # => true
|
1431
|
+
# (3...7.0).equiv?(3..6) # => true
|
1432
|
+
# (3...7.0).equiv?(3.0..6) # => false
|
1433
|
+
#
|
1434
|
+
# @param other [Range, RangeExtd]
|
1435
|
+
def equiv?(other)
|
1436
|
+
t_or_f = (defined?(self.begin.succ) && defined?(other.begin.succ) && defined?(other.end) && defined?(other.exclude_end?))
|
1437
|
+
if ! t_or_f
|
1438
|
+
return(self == other) # succ() for begin is not defined.
|
1439
|
+
else
|
1440
|
+
# Checking the begins.
|
1441
|
+
if defined?(other.exclude_begin?) && other.exclude_begin? # The other is RangeExtd with exclude_begin?==true.
|
1442
|
+
if self.begin != other.begin.succ
|
1443
|
+
return false
|
1444
|
+
else
|
1445
|
+
# Pass
|
1446
|
+
end
|
1447
|
+
elsif (self.begin != other.begin)
|
1448
|
+
return false
|
1449
|
+
end
|
1450
|
+
|
1451
|
+
# Now, the begins agreed. Checking the ends.
|
1452
|
+
if (self.end == other.end)
|
1453
|
+
if (exclude_end? ^! other.exclude_end?)
|
1454
|
+
return true
|
1455
|
+
else
|
1456
|
+
return false
|
1457
|
+
end
|
1458
|
+
else # if (self.end == other.end)
|
1459
|
+
if (exclude_end? ^! other.exclude_end?)
|
1460
|
+
return false
|
1461
|
+
elsif ( exclude_end? && defined?(other.end.succ) && (self.end == other.end.succ)) ||
|
1462
|
+
(other.exclude_end? && defined?( self.end.succ) && (self.end.succ == other.end))
|
1463
|
+
return true
|
1464
|
+
else
|
1465
|
+
return false
|
1466
|
+
end
|
1467
|
+
end # if (self.end == other.end)
|
1468
|
+
end # if ! t_or_f
|
1469
|
+
|
1470
|
+
end # def equiv?(other)
|
1471
|
+
|
1472
|
+
|
1348
1473
|
############## pravate methods of Range ##############
|
1349
1474
|
|
1350
1475
|
private
|
data/range_extd.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{range_extd}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.4.0"
|
6
6
|
# s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
7
7
|
# s.executables << 'hola'
|
8
8
|
# s.bindir = 'bin'
|
9
9
|
s.authors = ["Masa Sakano"]
|
10
|
-
s.date = %q{2014-05-
|
10
|
+
s.date = %q{2014-05-10}
|
11
11
|
s.summary = %q{RangeExtd - Extended Range class with exclude_begin and open-ends}
|
12
12
|
s.description = %q{Package for a subclass of Range, RangeExtd and RangeExtd::Infinity. The former defines a range that enables an exclusion of the begin boundary, in addition to the end boundary as in the built-in Range, and accepts open-ended ranges to infinity for either (or both) positive/negative direction. The latter has the two constant objects, POSITIVE and NEGATIVE, and they are a generalised Infinity of Float::INFINITY to any Comparable objects.}
|
13
13
|
# s.email = %q{abc@example.com}
|
data/test/test_range_extd.rb
CHANGED
@@ -1122,6 +1122,85 @@ return
|
|
1122
1122
|
end # def test_Range_nullfunc
|
1123
1123
|
|
1124
1124
|
|
1125
|
+
def test_Range_equiv
|
1126
|
+
r1 = (2..5)
|
1127
|
+
r2 = (2...7)
|
1128
|
+
assert !r1.equiv?("Q")
|
1129
|
+
assert !r1.equiv?(2.0..3.1)
|
1130
|
+
assert r1.equiv?(2.0..5.0)
|
1131
|
+
assert (2.0..5.0).equiv?(r1)
|
1132
|
+
assert (2.0..5.0).equiv?(2.0..5.0)
|
1133
|
+
assert !r1.equiv?(RangeExtd(2..5,true))
|
1134
|
+
assert !r1.equiv?(1..5)
|
1135
|
+
assert r1.equiv?(2..5)
|
1136
|
+
assert r2.equiv?(2...7)
|
1137
|
+
assert r1.equiv?(RangeExtd(1..5,true))
|
1138
|
+
assert !r1.equiv?(2...5)
|
1139
|
+
assert !r2.equiv?(2..7)
|
1140
|
+
assert !r1.equiv?(2..6)
|
1141
|
+
assert !r2.equiv?(2...8)
|
1142
|
+
assert r1.equiv?(2...6)
|
1143
|
+
assert r1.equiv?(RangeExtd(1...6,true))
|
1144
|
+
assert r2.equiv?(2..6)
|
1145
|
+
assert r2.equiv?(RangeExtd(1..6,true))
|
1146
|
+
assert !r1.equiv?(2...9)
|
1147
|
+
assert !r2.equiv?(2..9)
|
1148
|
+
assert !r1.equiv?(RangeExtd(1...9,true))
|
1149
|
+
assert !r2.equiv?(RangeExtd(1..9,true))
|
1150
|
+
assert (3...7.0).equiv?(3..6) # Because begin.succ is defined.
|
1151
|
+
assert !(3...7.0).equiv?(3.0..6) # Because begin.succ is not defined.
|
1152
|
+
end # def test_Range_equiv
|
1153
|
+
|
1154
|
+
|
1155
|
+
def test_RangeExtd_equiv
|
1156
|
+
r1 = RangeExtd(2..5)
|
1157
|
+
r2 = RangeExtd(2...7)
|
1158
|
+
r3 = RangeExtd(2..5,true)
|
1159
|
+
r4 = RangeExtd(2...7,true)
|
1160
|
+
assert !r1.equiv?("Q")
|
1161
|
+
assert !r1.equiv?(2.0..3.1)
|
1162
|
+
assert r1.equiv?(2.0..5.0)
|
1163
|
+
assert (2.0..5.0).equiv?(r1)
|
1164
|
+
assert (2.0..5.0).equiv?(2.0..5.0)
|
1165
|
+
assert r2.equiv?(2.0...7.0)
|
1166
|
+
assert r4.equiv?(RangeExtd(2.0...7.0,true))
|
1167
|
+
assert !r1.equiv?(RangeExtd(2..5,true))
|
1168
|
+
assert !r2.equiv?(r4)
|
1169
|
+
assert !r3.equiv?(2..5)
|
1170
|
+
assert !r4.equiv?(2...7)
|
1171
|
+
assert !r1.equiv?(1..5)
|
1172
|
+
assert !r3.equiv?(RangeExtd(1..5,true))
|
1173
|
+
assert !r1.equiv?(RangeExtd(4..5,true))
|
1174
|
+
assert !r3.equiv?(4..5)
|
1175
|
+
assert r1.equiv?(2..5)
|
1176
|
+
assert r2.equiv?(2...7)
|
1177
|
+
assert r1.equiv?(RangeExtd(1..5,true))
|
1178
|
+
assert r2.equiv?(RangeExtd(1...7,true))
|
1179
|
+
assert r3.equiv?(3..5)
|
1180
|
+
assert r4.equiv?(3...7)
|
1181
|
+
assert !r1.equiv?(RangeExtd(1...5,true))
|
1182
|
+
assert !r2.equiv?(RangeExtd(1..7,true))
|
1183
|
+
assert !r3.equiv?(3...5)
|
1184
|
+
assert !r4.equiv?(3..7)
|
1185
|
+
assert !r1.equiv?(2..9)
|
1186
|
+
assert !r1.equiv?(RangeExtd(1..9,true))
|
1187
|
+
assert !r2.equiv?(RangeExtd(1...9,true))
|
1188
|
+
assert !r3.equiv?(3..9)
|
1189
|
+
assert !r4.equiv?(3...9)
|
1190
|
+
assert r1.equiv?(2...6)
|
1191
|
+
assert r1.equiv?(RangeExtd(1...6,true))
|
1192
|
+
assert r2.equiv?(RangeExtd(1..6,true))
|
1193
|
+
assert r3.equiv?(3...6)
|
1194
|
+
assert r4.equiv?(3..6)
|
1195
|
+
assert !r4.equiv?(3.0..6.0)
|
1196
|
+
assert !r1.equiv?(2...9)
|
1197
|
+
assert !r1.equiv?(RangeExtd(1...9,true))
|
1198
|
+
assert !r2.equiv?(RangeExtd(1..9,true))
|
1199
|
+
assert !r3.equiv?(3...9)
|
1200
|
+
assert !r4.equiv?(3..9)
|
1201
|
+
end # def test_RangeExtd_equiv
|
1202
|
+
|
1203
|
+
|
1125
1204
|
def test_RangeExtd_none
|
1126
1205
|
assert RangeExtd::NONE.is_none?
|
1127
1206
|
assert RangeExtd::NONE.valid?
|
@@ -1270,6 +1349,14 @@ return
|
|
1270
1349
|
assert !((?a..?z) === "cc")
|
1271
1350
|
assert !((?B..?z) === 'dd')
|
1272
1351
|
|
1352
|
+
# RangeExtd#equiv?
|
1353
|
+
assert RangeExtd(2...7,true).equiv?(3..6) # => true
|
1354
|
+
assert !RangeExtd(2...7,true).equiv?(3..6.0) # => false
|
1355
|
+
assert !RangeExtd(2...7,true).equiv?(3.0..6.0) # => false
|
1356
|
+
assert !RangeExtd(2...7,true).equiv?(3..6.5) # => false
|
1357
|
+
assert RangeExtd(2...7,true).equiv?(RangeExtd(2.0...7.0,true)) # => true
|
1358
|
+
assert RangeExtd(2...7,true).equiv?(3...7.0) # => true
|
1359
|
+
|
1273
1360
|
# RangeExtd#eql?bsearch
|
1274
1361
|
ary = [0, 4, 7, 10, 12]
|
1275
1362
|
assert_equal nil, (3...4).bsearch{ |i| ary[i] >= 11}
|
@@ -1384,12 +1471,12 @@ return
|
|
1384
1471
|
assert_equal "2...6", RangeExtd(2...6).to_s
|
1385
1472
|
assert_equal "2<..6", RangeExtd(2,6,1).to_s
|
1386
1473
|
|
1387
|
-
# Range
|
1474
|
+
# Range#==
|
1388
1475
|
assert !(1...1).valid?
|
1389
1476
|
assert !(nil...nil).valid?
|
1390
1477
|
assert !((1...1) == RangeExtd(1, 1, true, true)) # => false.
|
1391
1478
|
|
1392
|
-
# Range
|
1479
|
+
# Range#valid?
|
1393
1480
|
assert !(nil..nil).valid? # => false
|
1394
1481
|
assert (0..0).valid? # => true
|
1395
1482
|
assert !(0...0).valid? # => false
|
@@ -1399,7 +1486,7 @@ return
|
|
1399
1486
|
assert RangeExtd::NONE.valid? # => true
|
1400
1487
|
assert RangeExtd::ALL.valid? # => true
|
1401
1488
|
|
1402
|
-
# Range
|
1489
|
+
# Range#empty?
|
1403
1490
|
assert_equal nil, (nil..nil).empty? # => nil
|
1404
1491
|
assert_equal nil, (1...1).empty? # => nil
|
1405
1492
|
assert !(1..1).empty? # => false
|
@@ -1409,6 +1496,15 @@ return
|
|
1409
1496
|
assert RangeExtd(?a...?b, true).empty? # => true
|
1410
1497
|
assert RangeExtd::NONE.empty? # => true
|
1411
1498
|
|
1499
|
+
# Range#equiv?
|
1500
|
+
assert (3...7).equiv?(3..6) # => true
|
1501
|
+
assert !(3...7).equiv?(3..6.0) # => false
|
1502
|
+
assert !(3...7).equiv?(3.0..6.0) # => false
|
1503
|
+
assert !(3...7).equiv?(3.0..6.5) # => false
|
1504
|
+
assert (3...7).equiv?(3.0...7.0) # => false
|
1505
|
+
assert (3...7.0).equiv?(3..6) # => true
|
1506
|
+
assert !(3...7.0).equiv?(3.0..6) # => false
|
1507
|
+
|
1412
1508
|
# class Infinity
|
1413
1509
|
assert_equal -1, (?z <=> RangeExtd::Infinity::POSITIVE)
|
1414
1510
|
assert_equal 1, (RangeExtd::Infinity::POSITIVE <=> ?z)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: range_extd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masa Sakano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Package for a subclass of Range, RangeExtd and RangeExtd::Infinity. The
|
14
14
|
former defines a range that enables an exclusion of the begin boundary, in addition
|