hash-utils 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +16 -0
- data/CHANGES.txt +6 -0
- data/Gemfile +6 -4
- data/Gemfile.lock +29 -9
- data/README.md +1 -0
- data/Rakefile +13 -1
- data/TODO.txt +1 -1
- data/VERSION +1 -1
- data/hash-utils.gemspec +22 -15
- data/lib/hash-utils/string.rb +1 -1
- data/lib/hash-utils/stringio.rb +31 -12
- data/{test → tests.rb} +145 -163
- metadata +47 -14
data/.travis.yml
ADDED
data/CHANGES.txt
CHANGED
data/Gemfile
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
# Example:
|
4
|
-
gem "ruby-version", ">= 0"
|
4
|
+
gem "ruby-version", ">= 0.4.0"
|
5
5
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
-
gem "bundler"
|
10
|
-
gem "
|
11
|
-
gem "
|
9
|
+
gem "bundler"
|
10
|
+
gem "jeweler"
|
11
|
+
gem "rake"
|
12
|
+
gem "rspec"
|
13
|
+
gem "simplecov"
|
12
14
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,39 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
diff-lcs (1.1.3)
|
4
5
|
git (1.2.5)
|
5
|
-
|
6
|
+
jeweler (1.8.4)
|
7
|
+
bundler (~> 1.0)
|
6
8
|
git (>= 1.2.5)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.7.5)
|
12
|
+
multi_json (1.3.6)
|
13
|
+
rake (0.9.2.2)
|
14
|
+
rdoc (3.12)
|
15
|
+
json (~> 1.4)
|
16
|
+
rspec (2.11.0)
|
17
|
+
rspec-core (~> 2.11.0)
|
18
|
+
rspec-expectations (~> 2.11.0)
|
19
|
+
rspec-mocks (~> 2.11.0)
|
20
|
+
rspec-core (2.11.1)
|
21
|
+
rspec-expectations (2.11.3)
|
22
|
+
diff-lcs (~> 1.1.3)
|
23
|
+
rspec-mocks (2.11.3)
|
24
|
+
ruby-version (0.4.2)
|
25
|
+
simplecov (0.6.4)
|
26
|
+
multi_json (~> 1.0)
|
27
|
+
simplecov-html (~> 0.5.3)
|
28
|
+
simplecov-html (0.5.3)
|
11
29
|
|
12
30
|
PLATFORMS
|
13
31
|
ruby
|
14
32
|
|
15
33
|
DEPENDENCIES
|
16
|
-
bundler
|
17
|
-
|
18
|
-
|
19
|
-
|
34
|
+
bundler
|
35
|
+
jeweler
|
36
|
+
rake
|
37
|
+
rspec
|
38
|
+
ruby-version (>= 0.4.0)
|
39
|
+
simplecov
|
data/README.md
CHANGED
@@ -24,6 +24,7 @@ non-atomic and organized by better way.
|
|
24
24
|
- `Symbol` – 8 methods.
|
25
25
|
|
26
26
|
For full reference and methods lists, see **[documentation][3]**.
|
27
|
+
[![Build Status](https://secure.travis-ci.org/martinkozak/hash-utils.png)](http://travis-ci.org/martinkozak/hash-utils)
|
27
28
|
|
28
29
|
### Modularization
|
29
30
|
|
data/Rakefile
CHANGED
@@ -10,8 +10,10 @@ rescue Bundler::BundlerError => e
|
|
10
10
|
exit e.status_code
|
11
11
|
end
|
12
12
|
|
13
|
+
### Jeweler
|
14
|
+
|
13
15
|
require 'rake'
|
14
|
-
require '
|
16
|
+
require 'jeweler'
|
15
17
|
|
16
18
|
Jeweler::Tasks.new do |gem|
|
17
19
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
@@ -28,3 +30,13 @@ Jeweler::Tasks.new do |gem|
|
|
28
30
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
29
31
|
end
|
30
32
|
Jeweler::RubygemsDotOrgTasks.new
|
33
|
+
|
34
|
+
|
35
|
+
### RSpec
|
36
|
+
|
37
|
+
require 'rspec/core/rake_task'
|
38
|
+
|
39
|
+
RSpec::Core::RakeTask.new(:test) do |t|
|
40
|
+
t.pattern = 'tests.rb'
|
41
|
+
t.rspec_opts = '--format d -c'
|
42
|
+
end
|
data/TODO.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.2
|
data/hash-utils.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "hash-utils"
|
8
|
-
s.version = "2.0.
|
8
|
+
s.version = "2.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Martin Koz\u{e1}k"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-10-06"
|
13
13
|
s.email = "martinkozak@martinkozak.net"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
".document",
|
20
|
+
".travis.yml",
|
20
21
|
"CHANGES.txt",
|
21
22
|
"Gemfile",
|
22
23
|
"Gemfile.lock",
|
@@ -41,7 +42,7 @@ Gem::Specification.new do |s|
|
|
41
42
|
"lib/hash-utils/string.rb",
|
42
43
|
"lib/hash-utils/stringio.rb",
|
43
44
|
"lib/hash-utils/symbol.rb",
|
44
|
-
"
|
45
|
+
"tests.rb"
|
45
46
|
]
|
46
47
|
s.homepage = "http://github.com/martinkozak/hash-utils"
|
47
48
|
s.licenses = ["MIT"]
|
@@ -53,21 +54,27 @@ Gem::Specification.new do |s|
|
|
53
54
|
s.specification_version = 3
|
54
55
|
|
55
56
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
-
s.add_runtime_dependency(%q<ruby-version>, [">= 0"])
|
57
|
-
s.add_development_dependency(%q<bundler>, [">=
|
58
|
-
s.add_development_dependency(%q<
|
59
|
-
s.add_development_dependency(%q<
|
57
|
+
s.add_runtime_dependency(%q<ruby-version>, [">= 0.4.0"])
|
58
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
60
63
|
else
|
61
|
-
s.add_dependency(%q<ruby-version>, [">= 0"])
|
62
|
-
s.add_dependency(%q<bundler>, [">=
|
63
|
-
s.add_dependency(%q<
|
64
|
-
s.add_dependency(%q<
|
64
|
+
s.add_dependency(%q<ruby-version>, [">= 0.4.0"])
|
65
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
66
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
67
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
69
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
65
70
|
end
|
66
71
|
else
|
67
|
-
s.add_dependency(%q<ruby-version>, [">= 0"])
|
68
|
-
s.add_dependency(%q<bundler>, [">=
|
69
|
-
s.add_dependency(%q<
|
70
|
-
s.add_dependency(%q<
|
72
|
+
s.add_dependency(%q<ruby-version>, [">= 0.4.0"])
|
73
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
74
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
75
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
76
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
77
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
71
78
|
end
|
72
79
|
end
|
73
80
|
|
data/lib/hash-utils/string.rb
CHANGED
data/lib/hash-utils/stringio.rb
CHANGED
@@ -7,19 +7,38 @@ require "hash-utils/object"
|
|
7
7
|
# StringIO extension.
|
8
8
|
#
|
9
9
|
|
10
|
-
|
10
|
+
if Ruby::Engine != :rbx
|
11
|
+
class StringIO < Data
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
##
|
14
|
+
# Indicates, object is IO, so +IO+ or +StringIO+ class.
|
15
|
+
#
|
16
|
+
# @return [Boolean] +true+ if yes, +false+ in otherwise
|
17
|
+
# @since 0.14.0
|
18
|
+
#
|
19
|
+
|
20
|
+
if not self.__hash_utils_instance_respond_to? :io?
|
21
|
+
def io?
|
22
|
+
true
|
23
|
+
end
|
22
24
|
end
|
25
|
+
|
26
|
+
end
|
27
|
+
else
|
28
|
+
class StringIO < Object
|
29
|
+
|
30
|
+
##
|
31
|
+
# Indicates, object is IO, so +IO+ or +StringIO+ class.
|
32
|
+
#
|
33
|
+
# @return [Boolean] +true+ if yes, +false+ in otherwise
|
34
|
+
# @since 0.14.0
|
35
|
+
#
|
36
|
+
|
37
|
+
if not self.__hash_utils_instance_respond_to? :io?
|
38
|
+
def io?
|
39
|
+
true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
23
43
|
end
|
24
|
-
|
25
44
|
end
|
data/{test → tests.rb}
RENAMED
@@ -1,13 +1,17 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
|
-
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
# (c) 2011-2012 Martin Kozák (martinkozak@martinkozak.net)
|
4
4
|
|
5
5
|
$:.push("./lib")
|
6
6
|
$:.unshift("./lib")
|
7
7
|
|
8
|
+
require "rspec"
|
8
9
|
require "stringio"
|
10
|
+
|
11
|
+
require "simplecov"
|
12
|
+
SimpleCov.start
|
13
|
+
|
9
14
|
require "hash-utils"
|
10
|
-
require "riot"
|
11
15
|
|
12
16
|
|
13
17
|
## ARRAY
|
@@ -17,208 +21,185 @@ require "riot"
|
|
17
21
|
#
|
18
22
|
# doc. Jiří Souček
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
describe "Array" do
|
25
|
+
specify("#second") do
|
22
26
|
[1, 2, 3, 4, 5, 6, 7, 8].second == 2
|
23
27
|
end
|
24
|
-
|
28
|
+
specify("#third") do
|
25
29
|
[1, 2, 3, 4, 5, 6, 7, 8].third == 3
|
26
30
|
end
|
27
|
-
|
31
|
+
specify("#fourth") do
|
28
32
|
[1, 2, 3, 4, 5, 6, 7, 8].fourth == 4
|
29
33
|
end
|
30
|
-
|
34
|
+
specify("#fifth") do
|
31
35
|
[1, 2, 3, 4, 5, 6, 7, 8].fifth == 5
|
32
36
|
end
|
33
|
-
|
37
|
+
specify("#sixth") do
|
34
38
|
[1, 2, 3, 4, 5, 6, 7, 8].sixth == 6
|
35
39
|
end
|
36
|
-
|
40
|
+
specify("#seventh") do
|
37
41
|
[1, 2, 3, 4, 5, 6, 7, 8].seventh == 7
|
38
42
|
end
|
39
|
-
|
43
|
+
specify("#eighth") do
|
40
44
|
[1, 2, 3, 4, 5, 6, 7, 8].eighth == 8
|
41
45
|
end
|
42
|
-
|
46
|
+
specify("#array?") do
|
43
47
|
[1, 2, 3].array?
|
44
48
|
end
|
45
|
-
|
49
|
+
specify("#avg") do
|
46
50
|
[1, 2, 3].avg == 2
|
47
51
|
end
|
48
|
-
|
52
|
+
specify("#clean") do
|
49
53
|
t = [1, nil]
|
50
54
|
t = t.clean(1)
|
51
55
|
t == [nil]
|
52
56
|
end
|
53
|
-
|
57
|
+
specify("#clean!") do
|
54
58
|
t = [1, nil]
|
55
59
|
t.clean!(1)
|
56
60
|
t == [nil]
|
57
61
|
end
|
58
|
-
|
62
|
+
specify("#sum") do
|
59
63
|
[1, 2, 3].sum == 6
|
60
64
|
end
|
61
|
-
|
65
|
+
specify("#to_set") do
|
62
66
|
[1, 2, 3].to_set == Set::new([1, 2, 3])
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
66
70
|
## FALSECLASS
|
67
71
|
|
68
|
-
|
69
|
-
|
72
|
+
describe "FalseClass" do
|
73
|
+
specify("#boolean?") do
|
70
74
|
false.boolean?
|
71
75
|
end
|
72
|
-
|
76
|
+
specify("#convert") do
|
73
77
|
false.convert(:a, :b) == :b
|
74
78
|
end
|
75
|
-
|
79
|
+
specify("#false?") do
|
76
80
|
false.false?
|
77
81
|
end
|
78
|
-
|
82
|
+
specify("#to_i") do
|
79
83
|
false.to_i == 0
|
80
84
|
end
|
81
|
-
|
85
|
+
specify("#true?") do
|
82
86
|
not false.true?
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
86
90
|
## FILE
|
87
91
|
|
88
|
-
|
89
|
-
|
92
|
+
describe "File" do
|
93
|
+
specify("#touch") do
|
90
94
|
File.touch("./~test1")
|
91
95
|
File.exists? "./~test1"
|
92
96
|
end
|
93
|
-
|
97
|
+
specify("#write") do
|
94
98
|
File.write("./~test2", "some string")
|
95
99
|
File.read("./~test2") == "some string"
|
96
100
|
end
|
97
101
|
|
98
|
-
|
102
|
+
after(:all) do
|
99
103
|
File.unlink("./~test1")
|
100
104
|
File.unlink("./~test2")
|
101
105
|
end
|
102
106
|
end
|
103
107
|
|
104
|
-
## GEM
|
105
|
-
|
106
|
-
context "Gem" do
|
107
|
-
asserts("#available?") do
|
108
|
-
Gem::available? "hash-utils" and not Gem::available? "xxxxxxx"
|
109
|
-
end
|
110
|
-
asserts("#require_available") do
|
111
|
-
result = Gem::require_available("hash-utils")
|
112
|
-
|
113
|
-
begin
|
114
|
-
require "hash-utils"
|
115
|
-
rescue LoadError
|
116
|
-
result = false
|
117
|
-
end
|
118
|
-
|
119
|
-
result and not Gem::require_available("xxxxxxx")
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
108
|
## HASH
|
124
109
|
|
125
|
-
|
126
|
-
|
127
|
-
{ :a => 1, :b => 2 }
|
128
|
-
end
|
129
|
-
|
130
|
-
asserts("#avg") do
|
131
|
-
topic.avg == 1.5
|
110
|
+
describe "Hash" do
|
111
|
+
specify("#avg") do
|
112
|
+
{ :a => 1, :b => 2 }.avg == 1.5
|
132
113
|
end
|
133
|
-
|
114
|
+
specify("#clean") do
|
134
115
|
t = { :a => 1, :b => nil }
|
135
116
|
t = t.clean(1)
|
136
117
|
t == { :b => nil }
|
137
118
|
end
|
138
|
-
|
119
|
+
specify("#clean!") do
|
139
120
|
t = { :a => 1, :b => nil }
|
140
121
|
t.clean!(1)
|
141
122
|
t == { :b => nil }
|
142
123
|
end
|
143
|
-
|
124
|
+
specify("#compact") do
|
144
125
|
t = { :a => 1, :b => nil }
|
145
126
|
t = t.compact
|
146
127
|
t == { :a => 1 }
|
147
128
|
end
|
148
|
-
|
129
|
+
specify("#compact!") do
|
149
130
|
t = { :a => 1, :b => nil }
|
150
131
|
t.compact!
|
151
132
|
t == { :a => 1 }
|
152
133
|
end
|
153
|
-
|
134
|
+
specify("#flip") do
|
154
135
|
t = { :a => 1, :b => 2, :c => 2 }
|
155
136
|
result = t.flip
|
156
137
|
result == { 1 => :a, 2 => :c }
|
157
138
|
end
|
158
|
-
|
139
|
+
specify("#flip!") do
|
159
140
|
t = { :a => 1, :b => 2, :c => 2 }
|
160
141
|
t.flip!
|
161
142
|
t == { 1 => :a, 2 => :c }
|
162
143
|
end
|
163
|
-
|
144
|
+
specify("#get_pairs") do
|
164
145
|
h = { :a => 1, :b => 2, :c => 3 }
|
165
146
|
result = [ ]
|
166
147
|
h.get_pairs(:a, :c, :d) { |i| result << i }
|
167
148
|
result == [[:a, 1], [:c, 3]]
|
168
149
|
end
|
169
|
-
|
150
|
+
specify("#get_items") do
|
170
151
|
h = { :a => 1, :b => 2, :c => 3 }
|
171
152
|
h.get_items(:a, :c, :d) == { :a => 1, :c => 3 }
|
172
153
|
end
|
173
|
-
|
154
|
+
specify("#get_values") do
|
174
155
|
h = { :a => 1, :b => 2, :c => 3 }
|
175
156
|
h.get_values(:a, :c, :d) == [1, 3]
|
176
157
|
end
|
177
|
-
|
158
|
+
specify("#get_values") do
|
178
159
|
{ :a => 1, :b => 2, :c => 3 }.hash?
|
179
160
|
end
|
180
|
-
|
181
|
-
|
161
|
+
specify("#map_values") do
|
162
|
+
{ :a => 1, :b => 2 }.map_values { |i| i + 1 } == { :a => 2, :b => 3 }
|
182
163
|
end
|
183
|
-
|
184
|
-
t =
|
164
|
+
specify("#map_values!") do
|
165
|
+
t = { :a => 1, :b => 2 }
|
185
166
|
t.map_values! { |i| i + 1 }
|
186
167
|
t == { :a => 2, :b => 3 }
|
187
168
|
end
|
188
|
-
|
169
|
+
specify("#deep_merge") do
|
189
170
|
h1 = {:a => {:b => :c, :d => :e}}
|
190
171
|
h2 = {:a => {:d => :f, :h => :i}}
|
191
172
|
h = h1.deep_merge(h2)
|
192
173
|
(h == {:a => {:b => :c, :d => :f, :h => :i}}) and (h1 == {:a => {:b => :c, :d => :e}})
|
193
174
|
end
|
194
|
-
|
175
|
+
specify("#deep_merge!") do
|
195
176
|
h = {:a => {:b => :c, :d => :e}}
|
196
177
|
h.deep_merge!({:a => {:d => :f, :h => :i}})
|
197
178
|
h == {:a => {:b => :c, :d => :f, :h => :i}}
|
198
179
|
end
|
199
|
-
|
180
|
+
specify("#keys_to_sym") do
|
200
181
|
h = {"a" => "b", 2 => "c", "d" => "e"}
|
201
182
|
h.keys_to_sym == {:a => "b", 2 => "c", :d => "e"}
|
202
183
|
end
|
203
|
-
|
184
|
+
specify("#keys_to_sym!") do
|
204
185
|
h = {"a" => "b", 2 => "c", "d" => "e"}
|
205
186
|
h.keys_to_sym!
|
206
187
|
h == {:a => "b", 2 => "c", :d => "e"}
|
207
188
|
end
|
208
|
-
|
209
|
-
|
189
|
+
specify("#sum") do
|
190
|
+
{ :a => 1, :b => 2 }.sum == 3
|
210
191
|
end
|
211
|
-
|
192
|
+
specify("#take_pairs") do
|
212
193
|
h = { :a => 1, :b => 2, :c => 3 }
|
213
194
|
result = [ ]
|
214
195
|
h.take_pairs(:a, :c, :d) { |i| result << i }
|
215
196
|
result == [[:a, 1], [:c, 3], [:d, nil]]
|
216
197
|
end
|
217
|
-
|
198
|
+
specify("#take_items") do
|
218
199
|
h = { :a => 1, :b => 2, :c => 3 }
|
219
200
|
h.take_items(:a, :c, :d) == { :a => 1, :c => 3, :d => nil }
|
220
201
|
end
|
221
|
-
|
202
|
+
specify("#take_values") do
|
222
203
|
h = { :a => 1, :b => 2, :c => 3 }
|
223
204
|
h.take_values(:a, :c, :d) == [1, 3, nil]
|
224
205
|
end
|
@@ -227,22 +208,22 @@ end
|
|
227
208
|
|
228
209
|
## IO
|
229
210
|
|
230
|
-
|
231
|
-
|
211
|
+
describe "IO" do
|
212
|
+
specify("#io?") do
|
232
213
|
io = File::open("./~test", "w")
|
233
214
|
result = io.io?
|
234
215
|
io.close()
|
235
216
|
result
|
236
217
|
end
|
237
|
-
|
218
|
+
after(:all) do
|
238
219
|
File.unlink("./~test")
|
239
220
|
end
|
240
221
|
end
|
241
222
|
|
242
223
|
## MODULE
|
243
224
|
|
244
|
-
|
245
|
-
|
225
|
+
describe "Module" do
|
226
|
+
specify("#get_module") do
|
246
227
|
require "zlib"
|
247
228
|
Kernel.get_module("Zlib::Inflate") == Zlib::Inflate
|
248
229
|
end
|
@@ -250,169 +231,169 @@ end
|
|
250
231
|
|
251
232
|
## NILCLASS
|
252
233
|
|
253
|
-
|
254
|
-
|
234
|
+
describe "NilClass" do
|
235
|
+
specify("#to_boolean") do
|
255
236
|
nil.to_boolean("xyz") === false
|
256
237
|
end
|
257
238
|
end
|
258
239
|
|
259
240
|
## NUMERIC
|
260
241
|
|
261
|
-
|
262
|
-
|
242
|
+
describe "Numeric" do
|
243
|
+
specify("#compare") do
|
263
244
|
5.compare(1) == 1 and 5.compare(5) == 0 and 5.compare(7) == -1
|
264
245
|
end
|
265
|
-
|
246
|
+
specify("#negative?") do
|
266
247
|
not 5.negative? and -2.negative?
|
267
248
|
end
|
268
|
-
|
249
|
+
specify("#negative!") do
|
269
250
|
5.negative! == -5 and -5.negative! == -5
|
270
251
|
end
|
271
|
-
|
252
|
+
specify("#number?") do
|
272
253
|
5.number?
|
273
254
|
end
|
274
|
-
|
255
|
+
specify("#positive?") do
|
275
256
|
5.positive? and not -2.positive?
|
276
257
|
end
|
277
|
-
|
258
|
+
specify("#positive!") do
|
278
259
|
5.positive! == 5 and -5.positive! == 5
|
279
260
|
end
|
280
261
|
end
|
281
262
|
|
282
263
|
## OBJECT
|
283
264
|
|
284
|
-
|
285
|
-
|
265
|
+
describe "Object" do
|
266
|
+
specify("#**") do
|
286
267
|
"ab" ** 5 == ["ab", "ab", "ab", "ab", "ab"]
|
287
268
|
end
|
288
|
-
|
269
|
+
specify("#array?") do
|
289
270
|
not "".array? and [].array?
|
290
271
|
end
|
291
|
-
|
272
|
+
specify("#boolean?") do
|
292
273
|
true.boolean? and false.boolean? and not "".boolean?
|
293
274
|
end
|
294
|
-
|
275
|
+
specify("#enumerable?") do
|
295
276
|
[].enumerable? and not 5.enumerable?
|
296
277
|
end
|
297
|
-
|
278
|
+
specify("#false?") do
|
298
279
|
(false.false? == true) and ("string".false? == false)
|
299
280
|
end
|
300
|
-
|
281
|
+
specify("#hash?") do
|
301
282
|
not "".hash? and {}.hash?
|
302
283
|
end
|
303
|
-
|
284
|
+
specify("#in?") do
|
304
285
|
5.in? 1..7 and not 9.in? 1..7
|
305
286
|
end
|
306
|
-
|
287
|
+
specify("#instance_of_any?") do
|
307
288
|
"".instance_of_any? [String, Symbol] \
|
308
289
|
and not "".instance_of_any? [Integer, Float] \
|
309
290
|
and "".instance_of_any? String, Symbol
|
310
291
|
end
|
311
|
-
|
292
|
+
specify("#io?") do
|
312
293
|
not "".io?
|
313
294
|
end
|
314
|
-
|
295
|
+
specify("#kind_of_any?") do
|
315
296
|
"".kind_of_any? [String, Symbol] \
|
316
297
|
and not "".kind_of_any? [Integer, Float] \
|
317
298
|
and "".kind_of_any? String, Symbol
|
318
299
|
end
|
319
|
-
|
300
|
+
specify("#number?") do
|
320
301
|
not :abcd.number? and 5.number?
|
321
302
|
end
|
322
|
-
|
303
|
+
specify("#proc?") do
|
323
304
|
proc = Proc::new { }
|
324
305
|
not :abcd.proc? and proc.proc?
|
325
306
|
end
|
326
|
-
|
307
|
+
specify("#string?") do
|
327
308
|
"".string? and not 5.string?
|
328
309
|
end
|
329
|
-
|
310
|
+
specify("#symbol?") do
|
330
311
|
:abcd.symbol? and not 5.symbol?
|
331
312
|
end
|
332
|
-
|
313
|
+
specify("#to_b") do
|
333
314
|
(nil.to_b === false) and ("ab".to_b === true)
|
334
315
|
end
|
335
|
-
|
336
|
-
(
|
316
|
+
specify("#to_sym") do
|
317
|
+
("ab".to_sym === :ab) and (12.to_sym == :"12")
|
337
318
|
end
|
338
|
-
|
319
|
+
specify("#true?") do
|
339
320
|
(true.true? == true) and ("string".true? == false)
|
340
321
|
end
|
341
322
|
end
|
342
323
|
|
343
324
|
## STRING
|
344
325
|
|
345
|
-
|
346
|
-
|
326
|
+
describe "String" do
|
327
|
+
specify("#first") do
|
347
328
|
"abcdefgh".first == ?a
|
348
329
|
end
|
349
|
-
|
330
|
+
specify("#second") do
|
350
331
|
"abcdefgh".second == ?b
|
351
332
|
end
|
352
|
-
|
333
|
+
specify("#third") do
|
353
334
|
"abcdefgh".third == ?c
|
354
335
|
end
|
355
|
-
|
336
|
+
specify("#fourth") do
|
356
337
|
"abcdefgh".fourth == ?d
|
357
338
|
end
|
358
|
-
|
339
|
+
specify("#fifth") do
|
359
340
|
"abcdefgh".fifth == ?e
|
360
341
|
end
|
361
|
-
|
342
|
+
specify("#sixth") do
|
362
343
|
"abcdefgh".sixth == ?f
|
363
344
|
end
|
364
|
-
|
345
|
+
specify("#seventh") do
|
365
346
|
"abcdefgh".seventh == ?g
|
366
347
|
end
|
367
|
-
|
348
|
+
specify("#eighth") do
|
368
349
|
"abcdefgh".eighth == ?h
|
369
350
|
end
|
370
|
-
|
351
|
+
specify("#cut!") do
|
371
352
|
foo = "0123456789"
|
372
353
|
foo.cut! 3..5
|
373
354
|
foo == "345"
|
374
355
|
end
|
375
|
-
|
356
|
+
specify("#first_line") do
|
376
357
|
res = true
|
377
358
|
res &= "a\nb\nc\n".first_line == "a\n"
|
378
359
|
res &= "a".first_line == "a"
|
379
360
|
end
|
380
|
-
|
361
|
+
specify("#first_lines") do
|
381
362
|
res = true
|
382
363
|
res &= "a\nb".first_lines(2) == ["a\n", "b"]
|
383
364
|
res &= "a\nb\nc\n".first_lines(4) == ["a\n", "b\n", "c\n"]
|
384
365
|
end
|
385
|
-
|
366
|
+
specify("#interlace") do
|
386
367
|
"abc".interlace("123") == "a123b123c"
|
387
368
|
end
|
388
|
-
|
369
|
+
specify("#interlace!") do
|
389
370
|
foo = "abc"
|
390
371
|
foo.interlace! "123"
|
391
372
|
foo == "a123b123c"
|
392
373
|
end
|
393
|
-
|
374
|
+
specify("#last") do
|
394
375
|
"abc".last == ?c
|
395
376
|
end
|
396
|
-
|
377
|
+
specify("#last_line") do
|
397
378
|
res = true
|
398
379
|
res &= "a\nb\nc\n".last_line == ""
|
399
380
|
res &= "a\nb\nc".last_line == "c"
|
400
381
|
res &= "a".last_line == "a"
|
401
382
|
end
|
402
|
-
|
383
|
+
specify("#last_lines") do
|
403
384
|
res = true
|
404
385
|
res &= "a\nb".last_lines(2) == ["a\n", "b"]
|
405
386
|
res &= "a\nb\nc\n".last_lines(4) == ["a\n", "b\n", "c\n", ""]
|
406
387
|
end
|
407
|
-
|
388
|
+
specify("#lcfirst") do
|
408
389
|
str = "ABCD"
|
409
390
|
str.lcfirst == "aBCD" and str == "ABCD"
|
410
391
|
end
|
411
|
-
|
392
|
+
specify("#lcfirst!") do
|
412
393
|
str = "ABCD"
|
413
394
|
str.lcfirst! == "aBCD" and str == "aBCD"
|
414
395
|
end
|
415
|
-
|
396
|
+
specify("#pop") do
|
416
397
|
res = true
|
417
398
|
str = "abcd"
|
418
399
|
res &= str.pop == "d"
|
@@ -421,37 +402,37 @@ context "String" do
|
|
421
402
|
res &= str.pop(2) == "cd"
|
422
403
|
res &= str == "ab"
|
423
404
|
end
|
424
|
-
|
405
|
+
specify("#pop_line") do
|
425
406
|
res = true
|
426
407
|
str = "a\nb\nc\nd"
|
427
408
|
res &= str.pop_line == "d"
|
428
409
|
res &= str = "a\nb\nc\n"
|
429
410
|
end
|
430
|
-
|
411
|
+
specify("#pop_lines") do
|
431
412
|
res = true
|
432
413
|
str = "a\nb\nc\nd\n"
|
433
414
|
res &= str.pop_lines(2) == ["d\n", ""]
|
434
415
|
res &= str = "a\nb\nc\n"
|
435
416
|
end
|
436
|
-
|
417
|
+
specify("#push_line") do
|
437
418
|
res = true
|
438
419
|
str = "a\nb\nc\nd"
|
439
420
|
res &= str.push_line("1") == "a\nb\nc\nd\n1"
|
440
421
|
res &= str == "a\nb\nc\nd\n1"
|
441
422
|
end
|
442
|
-
|
423
|
+
specify("#push_lines") do
|
443
424
|
res = true
|
444
425
|
str = "a\nb\nc\nd"
|
445
426
|
res &= str.push_lines("1", "2") == "a\nb\nc\nd\n1\n2"
|
446
427
|
res &= str == "a\nb\nc\nd\n1\n2"
|
447
428
|
end
|
448
|
-
|
429
|
+
specify("#random") do
|
449
430
|
str1 = String::random(30)
|
450
431
|
str2 = String::random(30)
|
451
432
|
|
452
433
|
str1 != str2
|
453
434
|
end
|
454
|
-
|
435
|
+
specify("#shift") do
|
455
436
|
res = true
|
456
437
|
str = "abcd"
|
457
438
|
res &= str.shift == "a"
|
@@ -460,51 +441,51 @@ context "String" do
|
|
460
441
|
res &= str.shift(2) == "ab"
|
461
442
|
res &= str == "cd"
|
462
443
|
end
|
463
|
-
|
444
|
+
specify("#shift_line") do
|
464
445
|
res = true
|
465
446
|
str = "a\nb\nc\nd\n"
|
466
447
|
res &= str.shift_line == "a\n"
|
467
448
|
res &= str = "b\nc\nd\n"
|
468
449
|
end
|
469
|
-
|
450
|
+
specify("#shift_lines") do
|
470
451
|
res = true
|
471
452
|
str = "a\nb\nc\nd\n"
|
472
453
|
res &= str.shift_lines(2) == ["a\n", "b\n"]
|
473
454
|
res &= str = "c\nd\n"
|
474
455
|
end
|
475
|
-
|
456
|
+
specify("#string?") do
|
476
457
|
"abcd".string?
|
477
458
|
end
|
478
|
-
|
459
|
+
specify("#swap_with") do
|
479
460
|
foo = "abc"
|
480
461
|
bar = "123"
|
481
462
|
foo.swap_with(bar)
|
482
463
|
foo = "123" and bar = "abc"
|
483
464
|
end
|
484
|
-
|
465
|
+
specify("#to_boolean") do
|
485
466
|
"alfa".to_boolean("alfa") == true
|
486
467
|
end
|
487
|
-
|
468
|
+
specify("#ucfirst") do
|
488
469
|
str = "abcd"
|
489
470
|
str.ucfirst == "Abcd" and str == "abcd"
|
490
471
|
end
|
491
|
-
|
472
|
+
specify("#ucfirst!") do
|
492
473
|
str = "abcd"
|
493
474
|
str.ucfirst! == "Abcd" and str == "Abcd"
|
494
475
|
end
|
495
|
-
|
476
|
+
specify("#unshift") do
|
496
477
|
res = true
|
497
478
|
str = "abcd"
|
498
479
|
res &= str.unshift("123") == "123abcd"
|
499
480
|
res &= str == "123abcd"
|
500
481
|
end
|
501
|
-
|
482
|
+
specify("#unshift_line") do
|
502
483
|
res = true
|
503
484
|
str = "a\nb\nc\nd\n"
|
504
485
|
res &= str.unshift_line("1") == "1\na\nb\nc\nd\n"
|
505
486
|
res &= str == "1\na\nb\nc\nd\n"
|
506
487
|
end
|
507
|
-
|
488
|
+
specify("#unshift_lines") do
|
508
489
|
res = true
|
509
490
|
str = "a\nb\nc\nd\n"
|
510
491
|
res &= str.unshift_lines("1", "2") == "1\n2\na\nb\nc\nd\n"
|
@@ -515,60 +496,61 @@ end
|
|
515
496
|
|
516
497
|
## STRINGIO
|
517
498
|
|
518
|
-
|
519
|
-
|
499
|
+
describe "StringIO" do
|
500
|
+
specify("#io?") do
|
520
501
|
StringIO::new.io?
|
521
502
|
end
|
522
503
|
end
|
523
504
|
|
524
505
|
## SYMBOL
|
525
506
|
|
526
|
-
|
527
|
-
|
507
|
+
describe "Symbol" do
|
508
|
+
specify("#*") do
|
528
509
|
:a * 5 == :aaaaa
|
529
510
|
end
|
530
|
-
|
511
|
+
specify("#+") do
|
531
512
|
:a + :b == :ab
|
532
513
|
end
|
533
|
-
|
514
|
+
specify("#[]") do
|
534
515
|
:abcde[0...3] == "abc"
|
535
516
|
end
|
536
|
-
|
517
|
+
specify("#append") do
|
537
518
|
:abcd.append("efg") == :abcdefg
|
538
519
|
end
|
539
|
-
|
520
|
+
specify("#end_with?") do
|
540
521
|
:abcde.end_with? "ghi", "cde"
|
541
522
|
end
|
542
|
-
|
523
|
+
specify("#prepend") do
|
543
524
|
:abcd.prepend("012") == :"012abcd"
|
544
525
|
end
|
545
|
-
|
526
|
+
specify("#split") do
|
546
527
|
:ab_cd_ef.split("_", 2) == [:ab, :cd_ef]
|
547
528
|
end
|
548
|
-
|
529
|
+
specify("#start_with?") do
|
549
530
|
:abcde.start_with? "ghi", "abc"
|
550
531
|
end
|
551
|
-
|
532
|
+
specify("#strip") do
|
552
533
|
:" a ".strip == :a
|
553
534
|
end
|
554
535
|
end
|
555
536
|
|
556
537
|
## TRUECLASS
|
557
538
|
|
558
|
-
|
559
|
-
|
539
|
+
describe "TrueClass" do
|
540
|
+
specify("#boolean?") do
|
560
541
|
true.boolean?
|
561
542
|
end
|
562
|
-
|
543
|
+
specify("#convert") do
|
563
544
|
true.convert(:a, :b) == :a
|
564
545
|
end
|
565
|
-
|
546
|
+
specify("#false?") do
|
566
547
|
not true.false?
|
567
548
|
end
|
568
|
-
|
549
|
+
specify("#to_i") do
|
569
550
|
true.to_i == 1
|
570
551
|
end
|
571
|
-
|
552
|
+
specify("#true?") do
|
572
553
|
true.true?
|
573
554
|
end
|
574
555
|
end
|
556
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-version
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 0.4.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 0.4.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bundler
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,39 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: jeweler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
38
70
|
type: :development
|
39
71
|
prerelease: false
|
40
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,15 +74,15 @@ dependencies:
|
|
42
74
|
requirements:
|
43
75
|
- - ! '>='
|
44
76
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
77
|
+
version: '0'
|
46
78
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
79
|
+
name: rspec
|
48
80
|
requirement: !ruby/object:Gem::Requirement
|
49
81
|
none: false
|
50
82
|
requirements:
|
51
83
|
- - ! '>='
|
52
84
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
85
|
+
version: '0'
|
54
86
|
type: :development
|
55
87
|
prerelease: false
|
56
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,15 +90,15 @@ dependencies:
|
|
58
90
|
requirements:
|
59
91
|
- - ! '>='
|
60
92
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
93
|
+
version: '0'
|
62
94
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
95
|
+
name: simplecov
|
64
96
|
requirement: !ruby/object:Gem::Requirement
|
65
97
|
none: false
|
66
98
|
requirements:
|
67
99
|
- - ! '>='
|
68
100
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0
|
101
|
+
version: '0'
|
70
102
|
type: :development
|
71
103
|
prerelease: false
|
72
104
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +106,7 @@ dependencies:
|
|
74
106
|
requirements:
|
75
107
|
- - ! '>='
|
76
108
|
- !ruby/object:Gem::Version
|
77
|
-
version: 0
|
109
|
+
version: '0'
|
78
110
|
description:
|
79
111
|
email: martinkozak@martinkozak.net
|
80
112
|
executables: []
|
@@ -84,6 +116,7 @@ extra_rdoc_files:
|
|
84
116
|
- README.md
|
85
117
|
files:
|
86
118
|
- .document
|
119
|
+
- .travis.yml
|
87
120
|
- CHANGES.txt
|
88
121
|
- Gemfile
|
89
122
|
- Gemfile.lock
|
@@ -108,7 +141,7 @@ files:
|
|
108
141
|
- lib/hash-utils/string.rb
|
109
142
|
- lib/hash-utils/stringio.rb
|
110
143
|
- lib/hash-utils/symbol.rb
|
111
|
-
-
|
144
|
+
- tests.rb
|
112
145
|
homepage: http://github.com/martinkozak/hash-utils
|
113
146
|
licenses:
|
114
147
|
- MIT
|
@@ -124,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
157
|
version: '0'
|
125
158
|
segments:
|
126
159
|
- 0
|
127
|
-
hash:
|
160
|
+
hash: 4436198451928549294
|
128
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
162
|
none: false
|
130
163
|
requirements:
|