dohutil 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/doh/core_ext/hash.rb +0 -16
- data/test/core_ext/bigdecimal.dt.rb +30 -0
- data/test/{test_date.rb → core_ext/date.dt.rb} +2 -3
- data/test/{test_datewithtime.rb → core_ext/datewithtime.dt.rb} +2 -3
- data/test/core_ext/force_deep_copy.dt.rb +67 -0
- data/test/core_ext/string.dt.rb +85 -0
- metadata +25 -8
data/lib/doh/core_ext/hash.rb
CHANGED
@@ -2,20 +2,4 @@ class Hash
|
|
2
2
|
def to_h
|
3
3
|
self
|
4
4
|
end
|
5
|
-
|
6
|
-
def setnew(key, value)
|
7
|
-
store(key, value) unless key?(key)
|
8
|
-
end
|
9
|
-
|
10
|
-
def merge_with_remove(hash)
|
11
|
-
self.dup.merge_with_remove!(hash)
|
12
|
-
end
|
13
|
-
|
14
|
-
#merges the given hash with the current
|
15
|
-
#then removes any elements from the merged hash that have
|
16
|
-
#a value of nil in the hash argument
|
17
|
-
def merge_with_remove!(hash)
|
18
|
-
self.merge!(hash).reject! {|elem, value| hash.key?(elem) && hash[elem].nil?}
|
19
|
-
self
|
20
|
-
end
|
21
5
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'doh/core_ext/bigdecimal'
|
2
|
+
|
3
|
+
module Doh
|
4
|
+
|
5
|
+
class Test_core_ext_bigdecimal < DohTest::TestGroup
|
6
|
+
def test_to_dig_valid
|
7
|
+
assert_equal('0.00', BigDecimal('0').to_dig)
|
8
|
+
assert_equal('1.00', BigDecimal('1').to_dig)
|
9
|
+
assert_equal('1.10', BigDecimal('1.1').to_dig)
|
10
|
+
assert_equal('1.11', BigDecimal('1.11134').to_dig)
|
11
|
+
assert_equal('1.111', BigDecimal('1.1113456').to_dig(3))
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_to_dig_errors
|
15
|
+
assert_raises(ArgumentError) { BigDecimal('1').to_dig(-1) }
|
16
|
+
assert_raises(ArgumentError) { BigDecimal('1').to_dig(0) }
|
17
|
+
assert_equal('0.00', BigDecimal('NaN').to_dig)
|
18
|
+
assert_equal('0.00', BigDecimal('Infinity').to_dig)
|
19
|
+
assert_equal('0.00', BigDecimal('blah').to_dig)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_to_dig_doesnt_modify
|
23
|
+
bd = BigDecimal('1.11134')
|
24
|
+
assert_equal('1.11134', bd.to_s)
|
25
|
+
assert_equal('1.11', bd.to_dig)
|
26
|
+
assert_equal('1.11134', bd.to_s)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -1,9 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
require_relative '../lib/doh/core_ext/date'
|
1
|
+
require 'doh/core_ext/date'
|
3
2
|
|
4
3
|
module Doh
|
5
4
|
|
6
|
-
class Test_core_ext_date <
|
5
|
+
class Test_core_ext_date < DohTest::TestGroup
|
7
6
|
def test_weekday
|
8
7
|
Date.new(2007, 1, 15).upto(Date.new(2007, 1, 19)) { |date| assert(date.weekday?) }
|
9
8
|
assert(!Date.new(2007, 1, 13).weekday?)
|
@@ -1,9 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
require_relative '../lib/doh/core_ext/datewithtime'
|
1
|
+
require 'doh/core_ext/datewithtime'
|
3
2
|
|
4
3
|
module Doh
|
5
4
|
|
6
|
-
class Test_core_ext_datewithtime <
|
5
|
+
class Test_core_ext_datewithtime < DohTest::TestGroup
|
7
6
|
def test_next_second
|
8
7
|
assert_equal(DateTime.new(2009, 2, 10, 15, 30, 3), DateTime.new(2009, 2, 10, 15, 30, 2).next_second(1))
|
9
8
|
assert_equal(Time.new(2009, 2, 10, 15, 30, 3), Time.new(2009, 2, 10, 15, 30, 2).next_second(1))
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'doh/core_ext/force_deep_copy'
|
2
|
+
|
3
|
+
module Doh
|
4
|
+
|
5
|
+
class Parent
|
6
|
+
force_deep_copy :var1, :var2
|
7
|
+
attr_accessor :var1, :var2
|
8
|
+
end
|
9
|
+
|
10
|
+
class Child < Parent
|
11
|
+
force_deep_copy :var3
|
12
|
+
attr_accessor :var3
|
13
|
+
end
|
14
|
+
|
15
|
+
class ShallowParent
|
16
|
+
attr_accessor :var1, :var2
|
17
|
+
end
|
18
|
+
|
19
|
+
class Test_core_ext_force_deep_copy < DohTest::TestGroup
|
20
|
+
def test_regular_dup
|
21
|
+
parent = ShallowParent.new
|
22
|
+
parent.var1 = ['elem1']
|
23
|
+
parent.var2 = {'key1' => 'val1'}
|
24
|
+
parent2 = parent.dup
|
25
|
+
assert(parent2.var1.equal?(parent.var1))
|
26
|
+
assert(parent2.var2.equal?(parent.var2))
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_force_deep_copy
|
30
|
+
parent = Parent.new
|
31
|
+
parent.var1 = ['elem1']
|
32
|
+
parent.var2 = {'key1' => 'val1'}
|
33
|
+
parent2 = parent.dup
|
34
|
+
assert(!parent2.var1.equal?(parent.var1))
|
35
|
+
assert(!parent2.var2.equal?(parent.var2))
|
36
|
+
|
37
|
+
parent2.var1.push('elem2')
|
38
|
+
parent2.var2['key2'] = 'val2'
|
39
|
+
assert_equal(['elem1'], parent.var1)
|
40
|
+
assert_equal(['key1'], parent.var2.keys)
|
41
|
+
assert_equal(['val1'], parent.var2.values)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_force_deep_copy_inheritance
|
45
|
+
child = Child.new
|
46
|
+
child.var1 = ['elem1']
|
47
|
+
child.var2 = {'key1' => 'val1'}
|
48
|
+
child.var3 = Parent.new
|
49
|
+
child.var3.var1 = ['blah']
|
50
|
+
child2 = child.dup
|
51
|
+
assert(!child2.var1.equal?(child.var1))
|
52
|
+
assert(!child2.var2.equal?(child.var2))
|
53
|
+
assert(!child2.var3.equal?(child.var3))
|
54
|
+
|
55
|
+
child2.var1.push('elem2')
|
56
|
+
child2.var2['key2'] = 'val2'
|
57
|
+
child2.var3.var1.push(['smoe'])
|
58
|
+
child2.var3.var2 = 'val3'
|
59
|
+
assert_equal(['elem1'], child.var1)
|
60
|
+
assert_equal(['key1'], child.var2.keys)
|
61
|
+
assert_equal(['val1'], child.var2.values)
|
62
|
+
assert_equal(['blah'], child.var3.var1)
|
63
|
+
assert_equal(nil, child.var3.var2)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'doh/core_ext/string'
|
2
|
+
|
3
|
+
module Doh
|
4
|
+
|
5
|
+
class Test_core_ext_string < DohTest::TestGroup
|
6
|
+
def test_mid
|
7
|
+
str = 'smoe:blah'
|
8
|
+
assert_equal('smoe:blah', str.mid(0))
|
9
|
+
assert_equal('moe:blah', str.mid(1))
|
10
|
+
assert_equal('ah', str.mid(7))
|
11
|
+
assert_equal('h', str.mid(8))
|
12
|
+
assert_equal('', str.mid(9))
|
13
|
+
assert_equal(nil, str.mid(10))
|
14
|
+
assert_equal(nil, str.mid(11))
|
15
|
+
assert_equal('h', str.mid(-1))
|
16
|
+
assert_equal('ah', str.mid(-2))
|
17
|
+
assert_equal('moe:blah', str.mid(-8))
|
18
|
+
assert_equal('smoe:blah', str.mid(-9))
|
19
|
+
assert_equal(nil, str.mid(-10))
|
20
|
+
|
21
|
+
assert_equal('', str.mid(0, 0))
|
22
|
+
assert_equal('s', str.mid(0, 1))
|
23
|
+
assert_equal('smoe', str.mid(0, 4))
|
24
|
+
assert_equal('', str.mid(1, 0))
|
25
|
+
assert_equal('ah', str.mid(7, 4))
|
26
|
+
assert_equal('', str.mid(9, 0))
|
27
|
+
assert_equal('', str.mid(9, 10))
|
28
|
+
assert_equal('h', str.mid(-1, 10))
|
29
|
+
|
30
|
+
assert_equal(nil, str.mid(0, -1))
|
31
|
+
assert_equal(nil, str.mid(-1, -1))
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_after
|
35
|
+
str = 'smoe:blah:blee'
|
36
|
+
assert_equal(nil, str.after('notinthereatall'))
|
37
|
+
assert_equal('blah:blee', str.after(':'))
|
38
|
+
assert_equal('', str.after(':blee'))
|
39
|
+
assert_equal('blee', str.after('blah:'))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_rafter
|
43
|
+
str = 'smoe:blah:blee'
|
44
|
+
assert_equal(nil, str.rafter('notinthereatall'))
|
45
|
+
assert_equal('blee', str.rafter(':'))
|
46
|
+
assert_equal('', str.after(':blee'))
|
47
|
+
assert_equal('blee', str.after('blah:'))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_before
|
51
|
+
str = 'smoe:blah:blee'
|
52
|
+
assert_equal(nil, str.before('notinthereatall'))
|
53
|
+
assert_equal('smoe', str.before(':'))
|
54
|
+
assert_equal('', str.before('smoe:'))
|
55
|
+
assert_equal('smoe:blah', str.before(':blee'))
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_rbefore
|
59
|
+
str = 'smoe:blah:blee'
|
60
|
+
assert_equal(nil, str.rbefore('notinthereatall'))
|
61
|
+
assert_equal('smoe:blah', str.rbefore(':'))
|
62
|
+
assert_equal('', str.rbefore('smoe:'))
|
63
|
+
assert_equal('smoe:blah', str.rbefore(':blee'))
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_firstn
|
67
|
+
str = 'blah'
|
68
|
+
assert_equal(nil, str.firstn(-1))
|
69
|
+
assert_equal('', str.firstn(0))
|
70
|
+
assert_equal('b', str.firstn(1))
|
71
|
+
assert_equal('bl', str.firstn(2))
|
72
|
+
assert_equal('blah', str.firstn(100))
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_lastn
|
76
|
+
str = 'blah'
|
77
|
+
assert_equal(nil, str.lastn(-1))
|
78
|
+
assert_equal('', str.lastn(0))
|
79
|
+
assert_equal('h', str.lastn(1))
|
80
|
+
assert_equal('ah', str.lastn(2))
|
81
|
+
assert_equal('blah', str.lastn(100))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dohutil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-14 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: dohroot
|
17
|
-
requirement: &
|
17
|
+
requirement: &70099400285420 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,18 @@ dependencies:
|
|
22
22
|
version: 0.1.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70099400285420
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: dohtest
|
28
|
+
requirement: &70099400267060 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.7
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70099400267060
|
26
37
|
description: Tiny utilities, packaged together so they don't each have their own gem.
|
27
38
|
email:
|
28
39
|
- devinfo@atpsoft.com
|
@@ -50,8 +61,11 @@ files:
|
|
50
61
|
- lib/doh/http_helper.rb
|
51
62
|
- lib/doh/log/stub.rb
|
52
63
|
- lib/doh/to_display.rb
|
53
|
-
- test/
|
54
|
-
- test/
|
64
|
+
- test/core_ext/bigdecimal.dt.rb
|
65
|
+
- test/core_ext/date.dt.rb
|
66
|
+
- test/core_ext/datewithtime.dt.rb
|
67
|
+
- test/core_ext/force_deep_copy.dt.rb
|
68
|
+
- test/core_ext/string.dt.rb
|
55
69
|
- MIT-LICENSE
|
56
70
|
homepage: https://github.com/atpsoft/dohutil
|
57
71
|
licenses:
|
@@ -79,6 +93,9 @@ signing_key:
|
|
79
93
|
specification_version: 3
|
80
94
|
summary: assorted tiny utilities
|
81
95
|
test_files:
|
82
|
-
- test/
|
83
|
-
- test/
|
96
|
+
- test/core_ext/bigdecimal.dt.rb
|
97
|
+
- test/core_ext/date.dt.rb
|
98
|
+
- test/core_ext/datewithtime.dt.rb
|
99
|
+
- test/core_ext/force_deep_copy.dt.rb
|
100
|
+
- test/core_ext/string.dt.rb
|
84
101
|
has_rdoc:
|