active_object 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -6
- data/.rspec +3 -3
- data/CODE_OF_CONDUCT.md +13 -0
- data/LICENSE.txt +17 -18
- data/README.md +18 -0
- data/active_object.gemspec +4 -3
- data/bin/console +14 -0
- data/bin/rake +16 -0
- data/bin/setup +7 -0
- data/lib/active_object/string.rb +18 -0
- data/lib/active_object/version.rb +1 -1
- metadata +8 -24
- data/spec/lib/array_spec.rb +0 -125
- data/spec/lib/enumerable_spec.rb +0 -326
- data/spec/lib/hash_spec.rb +0 -191
- data/spec/lib/integer_spec.rb +0 -11
- data/spec/lib/numeric_spec.rb +0 -656
- data/spec/lib/object_spec.rb +0 -85
- data/spec/lib/range_spec.rb +0 -26
- data/spec/lib/string_spec.rb +0 -471
- data/spec/lib/time_spec.rb +0 -455
- data/spec/spec_helper.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b50729a90bddc311c59585834a86ad2c19a5d48
|
4
|
+
data.tar.gz: a947a8d5b05ab1a8c993ee0800c8772f2a01620e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a242ede6bd2219518280ae420a06546a4022497c79acb743849a23b815f1ea18e110625ffb41bd83d86cdca2d3ac886bd57ba03f8bc7348cb4221a3f128bf10
|
7
|
+
data.tar.gz: ab51dac6fa2df809586a0121f5858134bed826f1d398615629b815aff14261876844506a5578570b6150a642c15f5492999c57cf4eedfb09f649bdcbcd564b52
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2015 Juan Gomez
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1042,6 +1042,13 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1042
1042
|
"example_string.test".classify #=> "Test"
|
1043
1043
|
```
|
1044
1044
|
|
1045
|
+
####Constantize:####
|
1046
|
+
`constantize` converts a string in an object. `Rails Safe`
|
1047
|
+
|
1048
|
+
```ruby
|
1049
|
+
"Example::String".constantize #=> Class Object
|
1050
|
+
```
|
1051
|
+
|
1045
1052
|
####Dasherize:####
|
1046
1053
|
`dasherize` and `dasherize!` replaces underscores with dashes in the string. `Rails Safe`
|
1047
1054
|
|
@@ -1049,6 +1056,17 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1049
1056
|
"example_string".dasherize #=> "example-string"
|
1050
1057
|
```
|
1051
1058
|
|
1059
|
+
####Deconstantize:####
|
1060
|
+
`deconstantize` and `deconstantize!` removes the rightmost segment from the constant expression in the string. `Rails Safe`
|
1061
|
+
|
1062
|
+
```ruby
|
1063
|
+
"Example::String".deconstantize # => "Example"
|
1064
|
+
"::Example::String".deconstantize # => "::Example"
|
1065
|
+
"String".deconstantize # => ""
|
1066
|
+
"::String".deconstantize # => ""
|
1067
|
+
"".deconstantize # => ""
|
1068
|
+
```
|
1069
|
+
|
1052
1070
|
####Demodulize:####
|
1053
1071
|
`demodulize` and `demodulize!` removes the module part from the expression in the string. `Rails Safe`
|
1054
1072
|
|
data/active_object.gemspec
CHANGED
@@ -8,14 +8,15 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = ActiveObject::VERSION
|
9
9
|
spec.authors = ["Juan Gomez"]
|
10
10
|
spec.email = ["j.gomez@drexed.com"]
|
11
|
+
|
11
12
|
spec.summary = %q{Commonly used ruby object helpers.}
|
12
13
|
spec.description = %q{Class extensions of commonly used ruby object helpers.}
|
13
14
|
spec.homepage = "https://github.com/drexed/active_object"
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.
|
18
|
-
spec.
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
20
|
spec.require_paths = ["lib"]
|
20
21
|
|
21
22
|
spec.add_development_dependency "bundler"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "active_object"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rake' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rake', 'rake')
|
data/bin/setup
ADDED
data/lib/active_object/string.rb
CHANGED
@@ -49,6 +49,12 @@ class String
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
unless defined?(Rails)
|
53
|
+
def constantize
|
54
|
+
Object.const_get(self)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
52
58
|
unless defined?(Rails)
|
53
59
|
def dasherize
|
54
60
|
gsub(/_/, "-")
|
@@ -61,6 +67,18 @@ class String
|
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
70
|
+
unless defined?(Rails)
|
71
|
+
def deconstantize
|
72
|
+
to_s[0, rindex('::') || 0]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
unless defined?(Rails)
|
77
|
+
def deconstantize!
|
78
|
+
replace(deconstantize)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
64
82
|
unless defined?(Rails)
|
65
83
|
def demodulize
|
66
84
|
to_s.gsub(/^.*::/, "")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,11 +77,15 @@ files:
|
|
77
77
|
- ".gitignore"
|
78
78
|
- ".rspec"
|
79
79
|
- ".travis.yml"
|
80
|
+
- CODE_OF_CONDUCT.md
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE.txt
|
82
83
|
- README.md
|
83
84
|
- Rakefile
|
84
85
|
- active_object.gemspec
|
86
|
+
- bin/console
|
87
|
+
- bin/rake
|
88
|
+
- bin/setup
|
85
89
|
- lib/active_object.rb
|
86
90
|
- lib/active_object/array.rb
|
87
91
|
- lib/active_object/enumerable.rb
|
@@ -93,16 +97,6 @@ files:
|
|
93
97
|
- lib/active_object/string.rb
|
94
98
|
- lib/active_object/time.rb
|
95
99
|
- lib/active_object/version.rb
|
96
|
-
- spec/lib/array_spec.rb
|
97
|
-
- spec/lib/enumerable_spec.rb
|
98
|
-
- spec/lib/hash_spec.rb
|
99
|
-
- spec/lib/integer_spec.rb
|
100
|
-
- spec/lib/numeric_spec.rb
|
101
|
-
- spec/lib/object_spec.rb
|
102
|
-
- spec/lib/range_spec.rb
|
103
|
-
- spec/lib/string_spec.rb
|
104
|
-
- spec/lib/time_spec.rb
|
105
|
-
- spec/spec_helper.rb
|
106
100
|
homepage: https://github.com/drexed/active_object
|
107
101
|
licenses:
|
108
102
|
- MIT
|
@@ -127,14 +121,4 @@ rubygems_version: 2.4.8
|
|
127
121
|
signing_key:
|
128
122
|
specification_version: 4
|
129
123
|
summary: Commonly used ruby object helpers.
|
130
|
-
test_files:
|
131
|
-
- spec/lib/array_spec.rb
|
132
|
-
- spec/lib/enumerable_spec.rb
|
133
|
-
- spec/lib/hash_spec.rb
|
134
|
-
- spec/lib/integer_spec.rb
|
135
|
-
- spec/lib/numeric_spec.rb
|
136
|
-
- spec/lib/object_spec.rb
|
137
|
-
- spec/lib/range_spec.rb
|
138
|
-
- spec/lib/string_spec.rb
|
139
|
-
- spec/lib/time_spec.rb
|
140
|
-
- spec/spec_helper.rb
|
124
|
+
test_files: []
|
data/spec/lib/array_spec.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Array do
|
4
|
-
|
5
|
-
describe "#delete_first" do
|
6
|
-
it "to be [2, 3]" do
|
7
|
-
expect([1, 2, 3].delete_first).to eq([2, 3])
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#delete_last" do
|
12
|
-
it "to be [1, 2]" do
|
13
|
-
expect([1, 2, 3].delete_last).to eq([1, 2])
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#from" do
|
18
|
-
it "to be [1, 2, 3]" do
|
19
|
-
expect([1, 2, 3].from(0)).to eq([1, 2, 3])
|
20
|
-
end
|
21
|
-
|
22
|
-
it "to be [2, 3]" do
|
23
|
-
expect([1, 2, 3].from(1)).to eq([2, 3])
|
24
|
-
end
|
25
|
-
|
26
|
-
it "to be [3]" do
|
27
|
-
expect([1, 2, 3].from(-1)).to eq([3])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#groups" do
|
32
|
-
it "to be [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'] ['10']]" do
|
33
|
-
expect(%w(1 2 3 4 5 6 7 8 9 10).groups(3)).to eq([["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["10"]])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "#in_groups" do
|
38
|
-
it "to be [['1', '2', '3', '4'], ['5', '6', '7', nil], ['8', '9', '10', nil]]" do
|
39
|
-
expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups(3)).to eq([["1", "2", "3", "4"], ["5", "6", "7", nil], ["8", "9", "10", nil]])
|
40
|
-
end
|
41
|
-
|
42
|
-
it "to be [['1', '2', '3', '4'], ['5', '6', '7', ' '], ['8', '9', '10', ' ']]" do
|
43
|
-
expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups(3, ' ')).to eq([["1", "2", "3", "4"], ["5", "6", "7", ' '], ["8", "9", "10", " "]])
|
44
|
-
end
|
45
|
-
|
46
|
-
it "to be [['1', '2', '3', '4'], ['5', '6', '7'], ['8', '9', '10']]" do
|
47
|
-
expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups(3, false)).to eq([["1", "2", "3", "4"], ["5", "6", "7"], ["8", "9", "10"]])
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "#in_groups_of" do
|
52
|
-
it "to be [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'] ['10', nil, nil]]" do
|
53
|
-
expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3)).to eq([["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["10", nil, nil]])
|
54
|
-
end
|
55
|
-
|
56
|
-
it "to be [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'] ['10', ' ', ' ']]" do
|
57
|
-
expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3, ' ')).to eq([["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["10", " ", " "]])
|
58
|
-
end
|
59
|
-
|
60
|
-
it "to be [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'] ['10']]" do
|
61
|
-
expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3, false)).to eq([["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["10"]])
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "#split" do
|
66
|
-
it "to be [[1, 2], [4, 5]]" do
|
67
|
-
expect([1, 2, 3, 4, 5].split(3)).to eq([[1, 2], [4, 5]])
|
68
|
-
end
|
69
|
-
|
70
|
-
it "to be [[1, 2], [4, 5], [7, 8], [10]]" do
|
71
|
-
expect((1..10).to_a.split { |i| i % 3 == 0 }).to eq([[1, 2], [4, 5], [7, 8], [10]])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "#strip" do
|
76
|
-
it "to be ['this', 'is', 'a', 'test']" do
|
77
|
-
expect("this is a test".split(" ").strip).to eq(["this", "is", "a", "test"])
|
78
|
-
end
|
79
|
-
|
80
|
-
it "to be ['this', 'that']" do
|
81
|
-
expect(["this", "", "that", nil, false].strip).to eq(["this", "that"])
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#to" do
|
86
|
-
it "to be [1]" do
|
87
|
-
expect([1, 2, 3].to(0)).to eq([1])
|
88
|
-
end
|
89
|
-
|
90
|
-
it "to be [1, 2]" do
|
91
|
-
expect([1, 2, 3].to(1)).to eq([1, 2])
|
92
|
-
end
|
93
|
-
|
94
|
-
it "to be [1, 2, 3]" do
|
95
|
-
expect([1, 2, 3].to(-1)).to eq([1, 2, 3])
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "#to_sentence" do
|
100
|
-
it "to be ''" do
|
101
|
-
expect([].to_sentence).to eq('')
|
102
|
-
end
|
103
|
-
|
104
|
-
it "to be 'one'" do
|
105
|
-
expect(["one"].to_sentence).to eq("one")
|
106
|
-
end
|
107
|
-
|
108
|
-
it "to be 'one and two'" do
|
109
|
-
expect(["one", "two"].to_sentence).to eq("one and two")
|
110
|
-
end
|
111
|
-
|
112
|
-
it "to be 'one, two, and three'" do
|
113
|
-
expect(["one", "two", "three"].to_sentence).to eq("one, two, and three")
|
114
|
-
end
|
115
|
-
|
116
|
-
it "to be 'one-two'" do
|
117
|
-
expect(["one", "two"].to_sentence(two_words_connector: '-')).to eq("one-two")
|
118
|
-
end
|
119
|
-
|
120
|
-
it "to be 'one or two or at least three'" do
|
121
|
-
expect(["one", "two", "three"].to_sentence(words_connector: ' or ', last_word_connector: ' or at least ')).to eq("one or two or at least three")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
data/spec/lib/enumerable_spec.rb
DELETED
@@ -1,326 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Enumerable do
|
4
|
-
|
5
|
-
describe "#difference" do
|
6
|
-
it "to be 0" do
|
7
|
-
expect([].difference).to eq(0)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "to be nil" do
|
11
|
-
expect([].difference(nil)).to eq(nil)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "to be -4" do
|
15
|
-
expect([1, 2, 3].difference).to eq(-4)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#divisible" do
|
20
|
-
it "to be 0" do
|
21
|
-
expect([].divisible).to eq(0)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "to be nil" do
|
25
|
-
expect([].divisible(nil)).to eq(nil)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "to be 2" do
|
29
|
-
expect([16, 4, 2].divisible).to eq(2)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#drop_last" do
|
34
|
-
it "to be []" do
|
35
|
-
expect([].drop_last(1)).to eq([])
|
36
|
-
end
|
37
|
-
|
38
|
-
it "to be [1, 2]" do
|
39
|
-
expect([1, 2, 3].drop_last(1)).to eq([1, 2])
|
40
|
-
end
|
41
|
-
|
42
|
-
it "to be [1]" do
|
43
|
-
expect([1, 2, 3].drop_last(2)).to eq([1])
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#drop_last_if" do
|
48
|
-
it "to be []" do
|
49
|
-
expect([].take_last_if(&:odd?)).to eq([])
|
50
|
-
end
|
51
|
-
|
52
|
-
it "to be [1, 2]" do
|
53
|
-
expect([1, 2, 3].drop_last_if(&:odd?)).to eq([1, 2])
|
54
|
-
end
|
55
|
-
|
56
|
-
it "to be [1, 2, 3, 4]" do
|
57
|
-
expect([1, 2, 3, 4].drop_last_if(&:odd?)).to eq([1, 2, 3, 4])
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#exactly?" do
|
62
|
-
it "to be true" do
|
63
|
-
expect([1, false, nil].exactly?(1)).to eq(true)
|
64
|
-
expect([false, nil].exactly?(0)).to eq(true)
|
65
|
-
expect([1, 2, 3].exactly?(3)).to eq(true)
|
66
|
-
expect([1, 2, 3, 4].exactly?(1) { |n| n > 3 }).to eq(true)
|
67
|
-
expect([1, 2, 3, 4].exactly?(2, &:even?)).to eq(true)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "to be false" do
|
71
|
-
expect([].exactly?(1)).to eq(false)
|
72
|
-
expect([1, false, nil].exactly?(3)).to eq(false)
|
73
|
-
expect([1, 1, 3, 3].exactly?(2, &:even?)).to eq(false)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "#exclude?" do
|
78
|
-
it "to be true" do
|
79
|
-
expect([1, 2, 3].exclude?(4)).to eq(true)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "to be false" do
|
83
|
-
expect([1, 2, 3].exclude?(3)).to eq(false)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "#exponential" do
|
88
|
-
it "to be 0" do
|
89
|
-
expect([].exponential).to eq(0)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "to be nil" do
|
93
|
-
expect([].exponential(nil)).to eq(nil)
|
94
|
-
end
|
95
|
-
|
96
|
-
it "to be 4096" do
|
97
|
-
expect([2, 3, 4].exponential).to eq(4096)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "#frequencies" do
|
102
|
-
it "to be {}" do
|
103
|
-
expect([].frequencies).to eq({})
|
104
|
-
end
|
105
|
-
|
106
|
-
it "to be { 1 => 2, :symbol => 2, 'string' => 1, 3 => 1 }" do
|
107
|
-
expect([1, :symbol, 'string', 3, :symbol, 1].frequencies).to eq({ 1 => 2, :symbol => 2, 'string' => 1, 3 => 1 })
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "#many?" do
|
112
|
-
it "to be true" do
|
113
|
-
expect([1, 2, 3].many?).to eq(true)
|
114
|
-
expect([1, false, nil].many?).to eq(true)
|
115
|
-
expect([1, 2, 3, 4].many?(&:even?)).to eq(true)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "to be false" do
|
119
|
-
expect([].many?).to eq(false)
|
120
|
-
expect([1, 1, 3, 3].many?(&:even?)).to eq(false)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "#max" do
|
125
|
-
it "to be 0" do
|
126
|
-
expect([].max).to eq(0)
|
127
|
-
end
|
128
|
-
|
129
|
-
it "to be nil" do
|
130
|
-
expect([].max(nil)).to eq(nil)
|
131
|
-
end
|
132
|
-
|
133
|
-
it "to be 3" do
|
134
|
-
expect([2, 3, 1].max).to eq(3)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe "#min" do
|
139
|
-
it "to be 0" do
|
140
|
-
expect([].min).to eq(0)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "to be nil" do
|
144
|
-
expect([].min(nil)).to eq(nil)
|
145
|
-
end
|
146
|
-
|
147
|
-
it "to be 3" do
|
148
|
-
expect([2, 3, 1].min).to eq(1)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe "#mean" do
|
153
|
-
it "to be 0" do
|
154
|
-
expect([].mean).to eq(0)
|
155
|
-
end
|
156
|
-
|
157
|
-
it "to be nil" do
|
158
|
-
expect([].mean(nil)).to eq(nil)
|
159
|
-
end
|
160
|
-
|
161
|
-
it "to be 2" do
|
162
|
-
expect([1, 2, 3].mean).to eq(2)
|
163
|
-
end
|
164
|
-
|
165
|
-
it "to be 2.5" do
|
166
|
-
expect([1, 2, 3, 4].mean).to eq(2.5)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe '#median' do
|
171
|
-
it 'to be 0' do
|
172
|
-
expect([].median).to eq(0)
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'to be nil' do
|
176
|
-
expect([].median(nil)).to eq(nil)
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'to be 2' do
|
180
|
-
expect([1,2,6].median).to eq(2)
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'to be 2.5' do
|
184
|
-
expect([1,2,3,6].median).to eq(2.5)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe '#mode' do
|
189
|
-
it 'to be 0' do
|
190
|
-
expect([].mode).to eq(0)
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'to be nil' do
|
194
|
-
expect([].mode(nil)).to eq(nil)
|
195
|
-
expect([1,2,3].mode).to eq(nil)
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'to be 1' do
|
199
|
-
expect([1,1,2,46].mode).to eq(1)
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'to be 3.5' do
|
203
|
-
expect([3.5].mode).to eq(3.5)
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
describe "#multiple" do
|
208
|
-
it "to be 0" do
|
209
|
-
expect([].multiple).to eq(0)
|
210
|
-
end
|
211
|
-
|
212
|
-
it "to be nil" do
|
213
|
-
expect([].multiple(nil)).to eq(nil)
|
214
|
-
end
|
215
|
-
|
216
|
-
it "to be 6" do
|
217
|
-
expect([1, 2, 3].multiple).to eq(6)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
describe '#range' do
|
222
|
-
it 'to be 0' do
|
223
|
-
expect([].range).to eq(0)
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'to be nil' do
|
227
|
-
expect([].range(nil)).to eq(nil)
|
228
|
-
end
|
229
|
-
|
230
|
-
it 'to be 5' do
|
231
|
-
expect([1,2,6].range).to eq(5)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
describe "#several?" do
|
236
|
-
it "to be true" do
|
237
|
-
expect([1, 2, 3].several?).to eq(true)
|
238
|
-
expect([1, 2, 3, 4].several?(&:even?)).to eq(true)
|
239
|
-
end
|
240
|
-
|
241
|
-
it "to be false" do
|
242
|
-
expect([].several?).to eq(false)
|
243
|
-
expect([1, false, nil].several?).to eq(false)
|
244
|
-
expect([1, 1, 3, 3].several?(&:even?)).to eq(false)
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe '#standard_deviation' do
|
249
|
-
it 'to be 0' do
|
250
|
-
expect([].standard_deviation).to eq(0)
|
251
|
-
end
|
252
|
-
|
253
|
-
it 'to be nil' do
|
254
|
-
expect([].standard_deviation(nil)).to eq(nil)
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'to be 0' do
|
258
|
-
expect([1].standard_deviation).to eq(0)
|
259
|
-
end
|
260
|
-
|
261
|
-
it 'to be 2.6457513110645907' do
|
262
|
-
expect([1,2,6].standard_deviation).to eq(2.6457513110645907)
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
describe "#sum" do
|
267
|
-
it "to be 0" do
|
268
|
-
expect([].sum).to eq(0)
|
269
|
-
end
|
270
|
-
|
271
|
-
it "to be nil" do
|
272
|
-
expect([].sum(nil)).to eq(nil)
|
273
|
-
end
|
274
|
-
|
275
|
-
it "to be 6" do
|
276
|
-
expect([1, 2, 3].sum).to eq(6)
|
277
|
-
end
|
278
|
-
|
279
|
-
it "to be 'foobar'" do
|
280
|
-
expect(["foo", "bar"].sum).to eq("foobar")
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
describe "#take_last" do
|
285
|
-
it "to be []" do
|
286
|
-
expect([].take_last(3)).to eq([])
|
287
|
-
end
|
288
|
-
|
289
|
-
it "to be [3]" do
|
290
|
-
expect([1, 2, 3].take_last(1)).to eq([3])
|
291
|
-
end
|
292
|
-
|
293
|
-
it "to be [2, 3]" do
|
294
|
-
expect([1, 2, 3].take_last(2)).to eq([2, 3])
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
describe "#take_last_if" do
|
299
|
-
it "to be []" do
|
300
|
-
expect([].take_last_if(&:odd?)).to eq([])
|
301
|
-
end
|
302
|
-
|
303
|
-
it "to be [3]" do
|
304
|
-
expect([1, 2, 3].take_last_if(&:odd?)).to eq([3])
|
305
|
-
end
|
306
|
-
|
307
|
-
it "to be [1, 2, 3, 4]" do
|
308
|
-
expect([1, 2, 3, 4].take_last_if(&:odd?)).to eq([])
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
describe '#variance' do
|
313
|
-
it 'to be 0' do
|
314
|
-
expect([].variance).to eq(0)
|
315
|
-
end
|
316
|
-
|
317
|
-
it 'to be nil' do
|
318
|
-
expect([].variance(nil)).to eq(nil)
|
319
|
-
end
|
320
|
-
|
321
|
-
it 'to be 7' do
|
322
|
-
expect([1,2,6].variance).to eq(7)
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
end
|