sarah 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.txt +4 -0
- data/lib/sarah.rb +9 -7
- data/sarah.gemspec +2 -2
- data/test/16v220.rb +31 -0
- metadata +5 -3
data/HISTORY.txt
CHANGED
data/lib/sarah.rb
CHANGED
@@ -60,11 +60,11 @@
|
|
60
60
|
# @author Brian Katzung (briank@kappacs.com), Kappa Computer Solutions, LLC
|
61
61
|
# @copyright 2013-2014 Brian Katzung and Kappa Computer Solutions, LLC
|
62
62
|
# @license MIT License
|
63
|
-
# @version 2.
|
63
|
+
# @version 2.2.0
|
64
64
|
|
65
65
|
class Sarah
|
66
66
|
|
67
|
-
VERSION = "2.
|
67
|
+
VERSION = "2.2.0"
|
68
68
|
|
69
69
|
# Private attributes:
|
70
70
|
# seq [Array] An array of (zero-origin) sequential values.
|
@@ -550,17 +550,17 @@ class Sarah
|
|
550
550
|
#
|
551
551
|
# (#each_key alias since 2.0.0)
|
552
552
|
#
|
553
|
-
# @param which [:all|:ary|:rnd|:seq|:spr] The data structures over
|
554
|
-
# which to iterate. (Since 2.0.0)
|
553
|
+
# @param which [:all|:ary|:nsq|:rnd|:seq|:spr] The data structures over
|
554
|
+
# which to iterate. (Since 2.0.0; :nsq since 2.2.0)
|
555
555
|
# @return [Sarah]
|
556
556
|
def each (which = :all)
|
557
557
|
case which when :all, :ary, :seq
|
558
558
|
@seq.each_index { |i| yield i, @seq[i] }
|
559
559
|
end
|
560
|
-
case which when :all, :ary, :spr
|
560
|
+
case which when :all, :ary, :nsq, :spr
|
561
561
|
@spr.keys.sort.each { |i| yield i, @spr[i] }
|
562
562
|
end
|
563
|
-
case which when :all, :rnd
|
563
|
+
case which when :all, :nsq, :rnd
|
564
564
|
@rnd.each { |key, value| yield key, value }
|
565
565
|
end
|
566
566
|
self
|
@@ -574,13 +574,15 @@ class Sarah
|
|
574
574
|
|
575
575
|
# Is the array (or are parts of it) empty?
|
576
576
|
#
|
577
|
-
# @param which [:all|:ary|:rnd|:seq|:spr]
|
577
|
+
# @param which [:all|:ary|:nsq|:rnd|:seq|:spr] Which data structures to
|
578
|
+
# check. (:nsq since 2.2.0)
|
578
579
|
# @return [Boolean]
|
579
580
|
# @since 2.0.0
|
580
581
|
def empty? (which = :all)
|
581
582
|
case which
|
582
583
|
when :all then @seq.empty? && @spr.empty? && @rnd.empty?
|
583
584
|
when :ary then @seq.empty? && @spr.empty?
|
585
|
+
when :nsq then @spr.empty? && @rnd.empty?
|
584
586
|
when :rnd then @rnd.empty?
|
585
587
|
when :seq then @seq.empty?
|
586
588
|
when :spr then @spr.empty?
|
data/sarah.gemspec
CHANGED
data/test/16v220.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'sarah'
|
3
|
+
|
4
|
+
# Test changes for version 2.2.0:
|
5
|
+
# :nsq for #each and #empty?
|
6
|
+
|
7
|
+
class TestSarah_16 < MiniTest::Unit::TestCase
|
8
|
+
|
9
|
+
def test_each
|
10
|
+
s = Sarah[1, 2, 5 => 'five', :a => ?a]
|
11
|
+
my_h = {}
|
12
|
+
s.each(:nsq) { |k, v| my_h[k] = v }
|
13
|
+
assert_equal s.to_h(:nsq), my_h, 'each :nsq matches to_h :nsq'
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_empty
|
17
|
+
s0 = Sarah[1, 2, 5 => 'five', :a => ?a]
|
18
|
+
s = Sarah.new s0
|
19
|
+
assert_equal false, s.empty?(:nsq), 'not empty? :nsq'
|
20
|
+
s.delete_at 5
|
21
|
+
assert_equal false, s.empty?(:nsq), 'not empty? :nsq after delete 5'
|
22
|
+
s = Sarah.new s0
|
23
|
+
s.delete_at :a
|
24
|
+
assert_equal false, s.empty?(:nsq), 'not empty? :nsq after delete a'
|
25
|
+
s.delete_at 5
|
26
|
+
assert_equal true, s.empty?(:nsq), 'empty? :nsq after delete 5 and a'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# END
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 2.
|
9
|
+
version: 2.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Brian Katzung
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2014-04-
|
17
|
+
date: 2014-04-11 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- test/14slice.rb
|
59
59
|
- test/01instance.rb
|
60
60
|
- test/12search.rb
|
61
|
+
- test/16v220.rb
|
61
62
|
- test/07inst_attr.rb
|
62
63
|
- test/03set_get.rb
|
63
64
|
- test/11each.rb
|
@@ -107,6 +108,7 @@ test_files:
|
|
107
108
|
- test/14slice.rb
|
108
109
|
- test/01instance.rb
|
109
110
|
- test/12search.rb
|
111
|
+
- test/16v220.rb
|
110
112
|
- test/07inst_attr.rb
|
111
113
|
- test/03set_get.rb
|
112
114
|
- test/11each.rb
|