utilise 0.4.0.pre.29 → 0.5.0.pre.42
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 +8 -8
- data/README.md +25 -2
- data/lib/utilise/array.rb +6 -0
- data/lib/utilise/augment/crash.rb +32 -0
- data/lib/utilise/augment/matchers.rb +1 -1
- data/lib/utilise/augment/modify.rb +31 -0
- data/lib/utilise/augment/time.rb +1 -0
- data/lib/utilise/fixnum.rb +6 -0
- data/lib/utilise/hash.rb +6 -0
- data/lib/utilise/hashie.rb +6 -0
- data/lib/utilise/object.rb +6 -0
- data/lib/utilise/string.rb +8 -0
- data/lib/utilise/symbol.rb +6 -0
- data/lib/utilise/time.rb +6 -0
- data/lib/utilise/version.rb +18 -2
- data/lib/utilise.rb +9 -2
- data/spec/spec_helper.rb +29 -0
- data/spec/{augment → utilise/augment}/array_spec.rb +17 -17
- data/spec/{augment → utilise/augment}/fixnum_spec.rb +6 -6
- data/spec/utilise/augment/hash_spec.rb +73 -0
- data/spec/utilise/augment/hashie_spec.rb +43 -0
- data/spec/{augment → utilise/augment}/object_spec.rb +8 -8
- data/spec/utilise/augment/string_spec.rb +99 -0
- data/spec/{augment → utilise/augment}/symbol_spec.rb +9 -9
- data/spec/utilise/augment/time_spec.rb +17 -0
- data/spec/utilise/version_spec.rb +13 -0
- metadata +96 -41
- data/lib/utilise/augment.rb +0 -38
- data/spec/augment/hash_spec.rb +0 -73
- data/spec/augment/string_spec.rb +0 -45
- data/spec/augment/time_spec.rb +0 -17
- data/spec/helper.rb +0 -8
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDZlMDY3ZmExYWUwZTE0YjFmNjhmNTkwNzcxNTM4NGQyOTI5ODFmMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTM0OTFhMzAwYzc2ODgzMWVjM2RlNWRlZDBiOGRkNjFiNmQzY2NmMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjgwMmI1ZjYwZjViYjAxYjIzZjM4OTVkNTUxNmY0NzRiOTQ1Y2MyNmUwMzU2
|
10
|
+
NDg1OTQ2YWFiOGUzYzdiZjA3YTQyOGM3MTlkZmY5NDlmNzY2ZjNlNjBiZTM3
|
11
|
+
ZmVkYTcwY2Q1NjhhNjA3YTkxMGVlZTdhYjE1NDE5ZTI1ZWYyYmE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjAyMTk2MzYyMzdkMmQ1ODA0MjUyMTQ2ODFiN2YxNzBkMTcyMDEzOWEzZDJm
|
14
|
+
MjUxZTIyYzNkM2IyNzgyMmYyY2ZjZWJjYmJjMzE0NDc3ZWY4ZGVmYjI2ZjVi
|
15
|
+
YjY1N2VlNjg4ODQyY2JiNjVmMzk0MzgzYzFjNDFhYjEzYjQxN2U=
|
data/README.md
CHANGED
@@ -17,8 +17,13 @@ Currently extends:
|
|
17
17
|
* Array
|
18
18
|
* Object
|
19
19
|
|
20
|
+
New Classes
|
21
|
+
* Hashie::Bash
|
22
|
+
|
20
23
|
Hashes and Arrays will have all values iterated.
|
21
24
|
|
25
|
+
## Usage
|
26
|
+
|
22
27
|
```ruby
|
23
28
|
gem install utilise
|
24
29
|
```
|
@@ -63,7 +68,7 @@ require 'utilise'
|
|
63
68
|
|
64
69
|
```ruby
|
65
70
|
Time.unique
|
66
|
-
=>
|
71
|
+
=> '80347765'
|
67
72
|
```
|
68
73
|
|
69
74
|
```ruby
|
@@ -76,6 +81,24 @@ false.bool?
|
|
76
81
|
1.bool?
|
77
82
|
=> false
|
78
83
|
|
79
|
-
|
84
|
+
'true'.bool?
|
80
85
|
=> false
|
81
86
|
```
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
'snake_case'.camel
|
90
|
+
=> 'SnakeCase'
|
91
|
+
|
92
|
+
'space case'.snake
|
93
|
+
=> 'space_case'
|
94
|
+
|
95
|
+
'CamelCase'.space
|
96
|
+
=> 'camel case'
|
97
|
+
```
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
hash = Hashie::Mash.new
|
101
|
+
=> {}
|
102
|
+
hash.key
|
103
|
+
=>
|
104
|
+
```
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'hashie/mash'
|
2
|
+
|
3
|
+
module Utilise
|
4
|
+
module Augment
|
5
|
+
# Module for hashie extended classes
|
6
|
+
module Crash
|
7
|
+
# Creates a hashie mash that raises an error when a key is not present
|
8
|
+
class Bash < Hashie::Mash
|
9
|
+
# The default proc to be used for the bash hash
|
10
|
+
DEFAULT_PROC = lambda do |hash, key|
|
11
|
+
fail NameError, "No value for:#{key} in #{hash.to_hash.inspect}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(source_hash = nil, default = nil, &blk)
|
15
|
+
default ? super(source_hash, default) : super(source_hash, &blk)
|
16
|
+
recursively_freeze(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
# recursively apply the default proc to all hashes
|
20
|
+
def recursively_freeze(obj)
|
21
|
+
case obj
|
22
|
+
when Array
|
23
|
+
obj.each { |o| recursively_freeze(o) }
|
24
|
+
when Hash
|
25
|
+
obj.default_proc = DEFAULT_PROC
|
26
|
+
recursively_freeze(obj.values)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Utilise
|
2
|
+
module Augment
|
3
|
+
# Extends classes that could be modified
|
4
|
+
module Modify
|
5
|
+
# Return a string in modified camel case
|
6
|
+
def camel
|
7
|
+
split_up.map(&:capitalize).join('')
|
8
|
+
end
|
9
|
+
|
10
|
+
# Return a string in snake case
|
11
|
+
def snake
|
12
|
+
split_up.join('_')
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return a string in regular space case
|
16
|
+
def space
|
17
|
+
split_up.join(' ')
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# Splits up the current string into an array and normalises it
|
23
|
+
def split_up
|
24
|
+
arr = split(/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?=_)|(?= )/)
|
25
|
+
arr.map!(&:downcase)
|
26
|
+
arr.map!(&:strip)
|
27
|
+
arr.map { |s| s.delete('_') }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/utilise/augment/time.rb
CHANGED
data/lib/utilise/hash.rb
ADDED
data/lib/utilise/time.rb
ADDED
data/lib/utilise/version.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Utilise
|
2
2
|
module Utilise
|
3
|
-
|
4
|
-
|
3
|
+
# The current gem version
|
4
|
+
VERSION = '0.5.0'
|
5
|
+
# The version update date
|
6
|
+
DATE = '2015-08-12'
|
7
|
+
# Debug output message
|
8
|
+
MSG = 'Version %s %s (running on %s-%s)'
|
9
|
+
|
10
|
+
module_function
|
11
|
+
|
12
|
+
# Outputs the current gem version
|
13
|
+
def version(debug = false)
|
14
|
+
if debug
|
15
|
+
format(MSG, VERSION, DATE, RUBY_ENGINE,
|
16
|
+
RUBY_VERSION)
|
17
|
+
else
|
18
|
+
VERSION
|
19
|
+
end
|
20
|
+
end
|
5
21
|
end
|
data/lib/utilise.rb
CHANGED
@@ -1,2 +1,9 @@
|
|
1
|
-
require 'utilise/
|
2
|
-
require 'utilise/
|
1
|
+
require 'utilise/array'
|
2
|
+
require 'utilise/fixnum'
|
3
|
+
require 'utilise/hash'
|
4
|
+
require 'utilise/hashie'
|
5
|
+
require 'utilise/object'
|
6
|
+
require 'utilise/string'
|
7
|
+
require 'utilise/symbol'
|
8
|
+
require 'utilise/time'
|
9
|
+
require 'utilise/version'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
require 'simplecov'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# rspec-expectations config goes here.
|
6
|
+
config.expect_with :rspec do |expectations|
|
7
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
8
|
+
# and `failure_message` of custom matchers include text for helper methods
|
9
|
+
# defined using `chain`, e.g.:
|
10
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
11
|
+
# # => "be bigger than 2 and smaller than 4"
|
12
|
+
# ...rather than:
|
13
|
+
# # => "be bigger than 2"
|
14
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
15
|
+
end
|
16
|
+
|
17
|
+
# rspec-mocks config goes here.
|
18
|
+
config.mock_with :rspec do |mocks|
|
19
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
20
|
+
# a real object. This is generally recommended, and will default to
|
21
|
+
# `true` in RSpec 4.
|
22
|
+
mocks.verify_partial_doubles = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Coveralls.wear!
|
27
|
+
SimpleCov.start
|
28
|
+
require 'utilise'
|
29
|
+
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Array do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe '#to_bool' do
|
5
|
+
it 'returns array with true when key value is 1' do
|
6
6
|
expect([1].to_bool).to eql([true])
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'returns array with false when key value is 0' do
|
10
10
|
expect([0].to_bool).to eql([false])
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'returns original array when key value is not 0 or 1' do
|
14
14
|
expect([2].to_bool).to eql([2])
|
15
15
|
end
|
16
16
|
|
@@ -34,40 +34,40 @@ describe Array do
|
|
34
34
|
expect(['value'].to_bool).to eql(['value'])
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'returns array with true when key value is :t' do
|
38
38
|
expect([:t].to_bool).to eql([true])
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it 'returns array with false when key value is :f' do
|
42
42
|
expect([:f].to_bool).to eql([false])
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it 'returns array with true when key value is :t' do
|
46
46
|
expect([:yes].to_bool).to eql([true])
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it 'returns array with false when key value is :f' do
|
50
50
|
expect([:f].to_bool).to eql([false])
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'returns array with true when key value is :true' do
|
54
54
|
expect([:true].to_bool).to eql([true])
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
57
|
+
it 'returns array with false when key value is :false' do
|
58
58
|
expect([:false].to_bool).to eql([false])
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'returns original array when key value is not :t or :n' do
|
62
62
|
expect([:symbol].to_bool).to eql([:symbol])
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
66
|
-
expect([1,0,'yes','false'
|
65
|
+
it 'returns array with multiple correct values' do
|
66
|
+
expect([1, 0, 'yes', 'false', :t, :f, :true, :false].to_bool).to eql([true, false, true, false, true, false, true, false])
|
67
67
|
end
|
68
68
|
|
69
|
-
it
|
70
|
-
expect([[1,[0]]].to_bool).to eql([[true,[false]]])
|
69
|
+
it 'returns multi level array with correct values' do
|
70
|
+
expect([[1, [0]]].to_bool).to eql([[true, [false]]])
|
71
71
|
end
|
72
72
|
end
|
73
|
-
end
|
73
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Fixnum do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe '#to_bool' do
|
5
|
+
it 'returns true when 1' do
|
6
6
|
expect(1.to_bool).to be true
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'returns false when 0' do
|
10
10
|
expect(0.to_bool).to be false
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'returns nil when not 0 or 1' do
|
14
14
|
expect(2.to_bool).to be nil
|
15
15
|
end
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
describe '#to_bool' do
|
5
|
+
it 'returns hash with true when key value is 1' do
|
6
|
+
expect({ 'key' => 1 }.to_bool).to eql('key' => true)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns hash with false when key value is 0' do
|
10
|
+
expect({ 'key' => 0 }.to_bool).to eql('key' => false)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns original hash when key value is not 0 or 1' do
|
14
|
+
expect({ 'key' => 2 }.to_bool).to eql('key' => 2)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns hash with true when key value is 'yes'" do
|
18
|
+
expect({ 'key' => 'yes' }.to_bool).to eql('key' => true)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns hash with false when key value is 'no'" do
|
22
|
+
expect({ 'key' => 'no' }.to_bool).to eql('key' => false)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns hash with true when key value is 'true'" do
|
26
|
+
expect({ 'key' => 'true' }.to_bool).to eql('key' => true)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns hash with false when key value is 'false'" do
|
30
|
+
expect({ 'key' => 'false' }.to_bool).to eql('key' => false)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns original hash when key value is not 'yes', 'no', 'true or 'false'" do
|
34
|
+
expect({ 'key' => 'value' }.to_bool).to eql('key' => 'value')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns hash with true when key value is :t' do
|
38
|
+
expect({ 'key' => :t }.to_bool).to eql('key' => true)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns hash with false when key value is :f' do
|
42
|
+
expect({ 'key' => :f }.to_bool).to eql('key' => false)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns hash with true when key value is :t' do
|
46
|
+
expect({ 'key' => :yes }.to_bool).to eql('key' => true)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns hash with false when key value is :f' do
|
50
|
+
expect({ 'key' => :no }.to_bool).to eql('key' => false)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns hash with true when key value is :true' do
|
54
|
+
expect({ 'key' => :true }.to_bool).to eql('key' => true)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns hash with false when key value is :false' do
|
58
|
+
expect({ 'key' => :false }.to_bool).to eql('key' => false)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns original hash when key value is not :t or :n' do
|
62
|
+
expect({ 'key' => :symbol }.to_bool).to eql('key' => :symbol)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns correct hash with multiple values' do
|
66
|
+
expect({ 'key0' => 1, 'key1' => 0, 'key2' => 'yes', 'key3' => 'false', 'key4' => :t, 'key4' => :f, 'key5' => :true, 'key6' => :false }.to_bool).to eql('key0' => true, 'key1' => false, 'key2' => true, 'key3' => false, 'key4' => true, 'key4' => false, 'key5' => true, 'key6' => false)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns correct multi-level hash with multiple values' do
|
70
|
+
expect({ 'key0' => { 'key1' => 1 }, 'key2' => { 'key3' => 0 } }.to_bool).to eql('key0' => { 'key1' => true }, 'key2' => { 'key3' => false })
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Utilise::Augment::Crash::Bash do
|
4
|
+
describe '.new' do
|
5
|
+
it 'returns a new hashie bash' do
|
6
|
+
expect(Hashie::Bash.new).to be_an_instance_of(Utilise::Augment::Crash::Bash)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'a bash with keys' do
|
11
|
+
before do
|
12
|
+
@hash = Hashie::Bash.new(a:1, b:{ c: 2, d: { e: 3, f: {} } })
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'has first layer keys' do
|
16
|
+
expect(@hash.a).to eql(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'has second layer keys' do
|
20
|
+
expect(@hash.b.c).to eql(2)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has third layer keys' do
|
24
|
+
expect(@hash.b.d.e).to eql(3)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'raises an error on the first layer' do
|
28
|
+
expect { @hash.x }.to raise_error(NameError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'raises an error on the second layer' do
|
32
|
+
expect { @hash.b.y }.to raise_error(NameError)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'raises an error on the third layer' do
|
36
|
+
expect { @hash.b.d.z }.to raise_error(NameError)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'raises the correct error' do
|
40
|
+
expect { @hash.x }.to raise_error(/No value for:\w+ in .+/)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe TrueClass do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe '#bool?' do
|
5
|
+
it 'returns true when matching' do
|
6
6
|
expect(true.bool?).to be true
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
describe FalseClass do
|
12
|
-
describe
|
13
|
-
it
|
12
|
+
describe '#bool?' do
|
13
|
+
it 'returns true when matching' do
|
14
14
|
expect(false.bool?).to be true
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe Object do
|
20
|
-
describe
|
21
|
-
it
|
22
|
-
expect(
|
20
|
+
describe '#bool?' do
|
21
|
+
it 'returns false when not matching' do
|
22
|
+
expect('true'.bool?).to be false
|
23
23
|
expect(0.bool?).to be false
|
24
24
|
expect(:false.bool?).to be false
|
25
25
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
describe '#to_bool' do
|
5
|
+
it 'returns true when true' do
|
6
|
+
expect('true'.to_bool).to be true
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns true when yes' do
|
10
|
+
expect('yes'.to_bool).to be true
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns true when t' do
|
14
|
+
expect('t'.to_bool).to be true
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns true when 1' do
|
18
|
+
expect('1'.to_bool).to be true
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns false when false' do
|
22
|
+
expect('false'.to_bool).to be false
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns false when no' do
|
26
|
+
expect('no'.to_bool).to be false
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns false when f' do
|
30
|
+
expect('f'.to_bool).to be false
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns false when 0' do
|
34
|
+
expect('0'.to_bool).to be false
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns nil when positive' do
|
38
|
+
expect('positive'.to_bool).to be nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns nil when negative' do
|
42
|
+
expect('negative'.to_bool).to be nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#camel' do
|
47
|
+
it 'returns a camel case from camel case' do
|
48
|
+
expect('CamelCase'.camel).to eq 'CamelCase'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns a camel case from snake case' do
|
52
|
+
expect('camel_case'.camel).to eq 'CamelCase'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns a camel case from space case' do
|
56
|
+
expect('camel case'.camel).to eq 'CamelCase'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns a camel case from complex camel case' do
|
60
|
+
expect('CamelONECase'.camel).to eq 'CamelOneCase'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#snake' do
|
65
|
+
it 'returns a snake case from camel case' do
|
66
|
+
expect('SnakeCase'.snake).to eq 'snake_case'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns a snake case from snake case' do
|
70
|
+
expect('snake_case'.snake).to eq 'snake_case'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns a snake case from space case' do
|
74
|
+
expect('snake case'.snake).to eq 'snake_case'
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'returns a snake case from complex camel case' do
|
78
|
+
expect('SnakeONECase'.snake).to eq 'snake_one_case'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#space' do
|
83
|
+
it 'returns a space case from camel case' do
|
84
|
+
expect('SpaceCase'.space).to eq 'space case'
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns a space case from snake case' do
|
88
|
+
expect('space_case'.space).to eq 'space case'
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'returns a space case from space case' do
|
92
|
+
expect('space case'.space).to eq 'space case'
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns a space case from complex camel case' do
|
96
|
+
expect('SpaceONECase'.space).to eq 'space one case'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -1,29 +1,29 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Symbol do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe '#to_bool' do
|
5
|
+
it 'returns true when true' do
|
6
6
|
expect(:true.to_bool).to be true
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'returns true when yes' do
|
10
10
|
expect(:yes.to_bool).to be true
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'returns true when t' do
|
14
14
|
expect(:t.to_bool).to be true
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'returns false when false' do
|
18
18
|
expect(:false.to_bool).to be false
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it 'returns false when no' do
|
22
22
|
expect(:no.to_bool).to be false
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it 'returns false when f' do
|
26
26
|
expect(:f.to_bool).to be false
|
27
27
|
end
|
28
28
|
end
|
29
|
-
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Time do
|
4
|
+
describe '#unique' do
|
5
|
+
it 'returns a string' do
|
6
|
+
expect(Time.unique.class).to be String
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns a string number' do
|
10
|
+
expect(Time.unique.to_i.class).to be Fixnum
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns a number from time to 3 decimal places' do
|
14
|
+
expect(Time.unique).to eq Time.now.strftime('%s%3N')[-8..-1]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Utilise do
|
4
|
+
describe '.version' do
|
5
|
+
it 'should return the current gem version' do
|
6
|
+
expect(Utilise.version).to eq('0.5.0')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return the current gem version with debug information' do
|
10
|
+
expect(Utilise.version(true)).to match(/Version \d\.\d\.\d \d{4}-\d{2}-\d{2} \(running on ruby\-\d+\.\d+\.\d+\)/)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,72 +1,114 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utilise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0.pre.42
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Slaughter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashie
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.6'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rake
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
16
44
|
requirements:
|
17
|
-
- -
|
45
|
+
- - ~>
|
18
46
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
47
|
+
version: '10.4'
|
20
48
|
type: :development
|
21
49
|
prerelease: false
|
22
50
|
version_requirements: !ruby/object:Gem::Requirement
|
23
51
|
requirements:
|
24
|
-
- -
|
52
|
+
- - ~>
|
25
53
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
54
|
+
version: '10.4'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
56
|
+
name: rspec
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
|
-
- -
|
59
|
+
- - ~>
|
32
60
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
61
|
+
version: '3.3'
|
34
62
|
type: :development
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
|
-
- -
|
66
|
+
- - ~>
|
39
67
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
68
|
+
version: '3.3'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
70
|
+
name: rubocop
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
|
-
- -
|
73
|
+
- - ~>
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
75
|
+
version: '0.33'
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- -
|
80
|
+
- - ~>
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
82
|
+
version: '0.33'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
58
100
|
requirements:
|
59
|
-
- -
|
101
|
+
- - ~>
|
60
102
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
103
|
+
version: 0.8.7
|
62
104
|
type: :development
|
63
105
|
prerelease: false
|
64
106
|
version_requirements: !ruby/object:Gem::Requirement
|
65
107
|
requirements:
|
66
|
-
- -
|
108
|
+
- - ~>
|
67
109
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
69
|
-
description:
|
110
|
+
version: 0.8.7
|
111
|
+
description: Extends a few ruby classes with helpful methods
|
70
112
|
email: b.p.slaughter@gmail.com
|
71
113
|
executables: []
|
72
114
|
extensions: []
|
@@ -75,19 +117,30 @@ files:
|
|
75
117
|
- License.md
|
76
118
|
- README.md
|
77
119
|
- lib/utilise.rb
|
78
|
-
- lib/utilise/
|
120
|
+
- lib/utilise/array.rb
|
79
121
|
- lib/utilise/augment/bool.rb
|
122
|
+
- lib/utilise/augment/crash.rb
|
80
123
|
- lib/utilise/augment/matchers.rb
|
124
|
+
- lib/utilise/augment/modify.rb
|
81
125
|
- lib/utilise/augment/time.rb
|
126
|
+
- lib/utilise/fixnum.rb
|
127
|
+
- lib/utilise/hash.rb
|
128
|
+
- lib/utilise/hashie.rb
|
129
|
+
- lib/utilise/object.rb
|
130
|
+
- lib/utilise/string.rb
|
131
|
+
- lib/utilise/symbol.rb
|
132
|
+
- lib/utilise/time.rb
|
82
133
|
- lib/utilise/version.rb
|
83
|
-
- spec/
|
84
|
-
- spec/augment/
|
85
|
-
- spec/augment/
|
86
|
-
- spec/augment/
|
87
|
-
- spec/augment/
|
88
|
-
- spec/augment/
|
89
|
-
- spec/augment/
|
90
|
-
- spec/
|
134
|
+
- spec/spec_helper.rb
|
135
|
+
- spec/utilise/augment/array_spec.rb
|
136
|
+
- spec/utilise/augment/fixnum_spec.rb
|
137
|
+
- spec/utilise/augment/hash_spec.rb
|
138
|
+
- spec/utilise/augment/hashie_spec.rb
|
139
|
+
- spec/utilise/augment/object_spec.rb
|
140
|
+
- spec/utilise/augment/string_spec.rb
|
141
|
+
- spec/utilise/augment/symbol_spec.rb
|
142
|
+
- spec/utilise/augment/time_spec.rb
|
143
|
+
- spec/utilise/version_spec.rb
|
91
144
|
homepage: http://benslaughter.github.io/utilise/
|
92
145
|
licenses:
|
93
146
|
- MIT
|
@@ -108,16 +161,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
161
|
version: 1.3.1
|
109
162
|
requirements: []
|
110
163
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
164
|
+
rubygems_version: 2.4.5
|
112
165
|
signing_key:
|
113
166
|
specification_version: 4
|
114
|
-
summary: Utilises a few extra
|
167
|
+
summary: Utilises a few extra methods
|
115
168
|
test_files:
|
116
|
-
- spec/
|
117
|
-
- spec/augment/time_spec.rb
|
118
|
-
- spec/augment/symbol_spec.rb
|
119
|
-
- spec/augment/
|
120
|
-
- spec/augment/
|
121
|
-
- spec/augment/
|
122
|
-
- spec/augment/
|
123
|
-
- spec/
|
169
|
+
- spec/utilise/version_spec.rb
|
170
|
+
- spec/utilise/augment/time_spec.rb
|
171
|
+
- spec/utilise/augment/symbol_spec.rb
|
172
|
+
- spec/utilise/augment/string_spec.rb
|
173
|
+
- spec/utilise/augment/object_spec.rb
|
174
|
+
- spec/utilise/augment/hashie_spec.rb
|
175
|
+
- spec/utilise/augment/hash_spec.rb
|
176
|
+
- spec/utilise/augment/fixnum_spec.rb
|
177
|
+
- spec/utilise/augment/array_spec.rb
|
178
|
+
- spec/spec_helper.rb
|
data/lib/utilise/augment.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'utilise/augment/bool.rb'
|
2
|
-
require 'utilise/augment/matchers.rb'
|
3
|
-
require 'utilise/augment/time.rb'
|
4
|
-
|
5
|
-
# Extend existing ruby class String
|
6
|
-
class String
|
7
|
-
include Utilise::Augment::Bool
|
8
|
-
end
|
9
|
-
|
10
|
-
# Extend existing ruby class Fixnum
|
11
|
-
class Fixnum
|
12
|
-
include Utilise::Augment::Bool
|
13
|
-
end
|
14
|
-
|
15
|
-
# Extend existing ruby class Symbol
|
16
|
-
class Symbol
|
17
|
-
include Utilise::Augment::Bool
|
18
|
-
end
|
19
|
-
|
20
|
-
# Extend existing ruby class Object
|
21
|
-
class Object
|
22
|
-
include Utilise::Augment::Matchers
|
23
|
-
end
|
24
|
-
|
25
|
-
# Extend existing ruby class Time
|
26
|
-
class Time
|
27
|
-
extend Utilise::Augment::Time
|
28
|
-
end
|
29
|
-
|
30
|
-
# Extend existing ruby class Hash
|
31
|
-
class Hash
|
32
|
-
include Utilise::Augment::Bool
|
33
|
-
end
|
34
|
-
|
35
|
-
# Extend existing ruby class Array
|
36
|
-
class Array
|
37
|
-
include Utilise::Augment::Bool
|
38
|
-
end
|
data/spec/augment/hash_spec.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Hash do
|
4
|
-
describe "#to_bool" do
|
5
|
-
it "returns hash with true when key value is 1" do
|
6
|
-
expect({'key' => 1}.to_bool).to eql({'key' => true})
|
7
|
-
end
|
8
|
-
|
9
|
-
it "returns hash with false when key value is 0" do
|
10
|
-
expect({'key' => 0}.to_bool).to eql({'key' => false})
|
11
|
-
end
|
12
|
-
|
13
|
-
it "returns original hash when key value is not 0 or 1" do
|
14
|
-
expect({'key' => 2}.to_bool).to eql({'key' => 2})
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns hash with true when key value is 'yes'" do
|
18
|
-
expect({'key' => 'yes'}.to_bool).to eql({'key' => true})
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns hash with false when key value is 'no'" do
|
22
|
-
expect({'key' => 'no'}.to_bool).to eql({'key' => false})
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns hash with true when key value is 'true'" do
|
26
|
-
expect({'key' => 'true'}.to_bool).to eql({'key' => true})
|
27
|
-
end
|
28
|
-
|
29
|
-
it "returns hash with false when key value is 'false'" do
|
30
|
-
expect({'key' => 'false'}.to_bool).to eql({'key' => false})
|
31
|
-
end
|
32
|
-
|
33
|
-
it "returns original hash when key value is not 'yes', 'no', 'true or 'false'" do
|
34
|
-
expect({'key' => 'value'}.to_bool).to eql({'key' => 'value'})
|
35
|
-
end
|
36
|
-
|
37
|
-
it "returns hash with true when key value is :t" do
|
38
|
-
expect({'key' => :t}.to_bool).to eql({'key' => true})
|
39
|
-
end
|
40
|
-
|
41
|
-
it "returns hash with false when key value is :f" do
|
42
|
-
expect({'key' => :f}.to_bool).to eql({'key' => false})
|
43
|
-
end
|
44
|
-
|
45
|
-
it "returns hash with true when key value is :t" do
|
46
|
-
expect({'key' => :yes}.to_bool).to eql({'key' => true})
|
47
|
-
end
|
48
|
-
|
49
|
-
it "returns hash with false when key value is :f" do
|
50
|
-
expect({'key' => :no}.to_bool).to eql({'key' => false})
|
51
|
-
end
|
52
|
-
|
53
|
-
it "returns hash with true when key value is :true" do
|
54
|
-
expect({'key' => :true}.to_bool).to eql({'key' => true})
|
55
|
-
end
|
56
|
-
|
57
|
-
it "returns hash with false when key value is :false" do
|
58
|
-
expect({'key' => :false}.to_bool).to eql({'key' => false})
|
59
|
-
end
|
60
|
-
|
61
|
-
it "returns original hash when key value is not :t or :n" do
|
62
|
-
expect({'key' => :symbol}.to_bool).to eql({'key' => :symbol})
|
63
|
-
end
|
64
|
-
|
65
|
-
it "returns correct hash with multiple values" do
|
66
|
-
expect({'key0'=> 1, 'key1'=>0, 'key2'=>'yes', 'key3'=>'false', 'key4'=>:t, 'key4'=>:f, 'key5'=>:true, 'key6' =>:false}.to_bool).to eql({'key0'=> true, 'key1'=>false, 'key2'=>true, 'key3'=>false, 'key4'=>true, 'key4'=>false, 'key5'=>true, 'key6' =>false})
|
67
|
-
end
|
68
|
-
|
69
|
-
it "returns correct multi-level hash with multiple values" do
|
70
|
-
expect({'key0' => {'key1' => 1}, 'key2' => {'key3' => 0}}.to_bool).to eql({'key0' => {'key1' => true}, 'key2' => {'key3' => false}})
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/spec/augment/string_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe String do
|
4
|
-
describe "#to_bool" do
|
5
|
-
it "returns true when true" do
|
6
|
-
expect('true'.to_bool).to be true
|
7
|
-
end
|
8
|
-
|
9
|
-
it "returns true when yes" do
|
10
|
-
expect('yes'.to_bool).to be true
|
11
|
-
end
|
12
|
-
|
13
|
-
it "returns true when t" do
|
14
|
-
expect('t'.to_bool).to be true
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns true when 1" do
|
18
|
-
expect('1'.to_bool).to be true
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns false when false" do
|
22
|
-
expect('false'.to_bool).to be false
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns false when no" do
|
26
|
-
expect('no'.to_bool).to be false
|
27
|
-
end
|
28
|
-
|
29
|
-
it "returns false when f" do
|
30
|
-
expect('f'.to_bool).to be false
|
31
|
-
end
|
32
|
-
|
33
|
-
it "returns false when 0" do
|
34
|
-
expect('0'.to_bool).to be false
|
35
|
-
end
|
36
|
-
|
37
|
-
it "returns nil when positive" do
|
38
|
-
expect('positive'.to_bool).to be nil
|
39
|
-
end
|
40
|
-
|
41
|
-
it "returns nil when negative" do
|
42
|
-
expect('negative'.to_bool).to be nil
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/spec/augment/time_spec.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Time do
|
4
|
-
describe "#unique" do
|
5
|
-
it "returns a string" do
|
6
|
-
expect(Time.unique.class).to be String
|
7
|
-
end
|
8
|
-
|
9
|
-
it "returns a string number" do
|
10
|
-
expect(Time.unique.to_i.class).to be Fixnum
|
11
|
-
end
|
12
|
-
|
13
|
-
it "returns a number from time to 3 decimal places" do
|
14
|
-
expect(Time.unique).to eq Time.now.strftime("%s%3N")[-8..-1]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|