facets 2.9.0.pre.1 → 2.9.0.pre.2
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.
- data/AUTHORS +1 -0
- data/COPYING +1 -2
- data/HISTORY.rdoc +16 -8
- data/lib/core/facets/hash/subset.rb +24 -0
- data/lib/core/facets/hash/zip.rb +18 -0
- data/lib/core/facets/kernel/try.rb +3 -3
- data/lib/core/facets/module/home.rb +90 -0
- data/lib/core/facets/module/homename.rb +1 -0
- data/lib/core/facets/module/housing.rb +1 -0
- data/lib/core/facets/module/modname.rb +1 -22
- data/lib/core/facets/na.rb +11 -5
- data/lib/core/facets/object/clone.rb +1 -0
- data/lib/core/facets/{kernel/try_dup.rb → object/dup.rb} +41 -35
- data/lib/core/facets/{kernel → object}/object_state.rb +15 -18
- data/lib/core/facets/object/replace.rb +43 -0
- data/lib/core/facets/object/try_dup.rb +1 -0
- data/lib/core/facets/string/cleanlines.rb +2 -0
- data/lib/core/facets/time/ago.rb +1 -1
- data/lib/core/facets/time/in.rb +1 -93
- data/lib/core/facets/time/less.rb +1 -0
- data/lib/core/facets/time/shift.rb +95 -0
- data/lib/more/facets/interval.rb +284 -0
- data/lib/more/facets/math.rb +6 -0
- data/lib/more/facets/math/abs.rb +8 -0
- data/lib/more/facets/math/acot.rb +8 -0
- data/lib/more/facets/math/acoth.rb +8 -0
- data/lib/more/facets/math/acsc.rb +8 -0
- data/lib/more/facets/math/acsch.rb +8 -0
- data/lib/more/facets/math/amd.rb +17 -0
- data/lib/more/facets/math/approx_equal.rb +15 -0
- data/lib/more/facets/math/asec.rb +8 -0
- data/lib/more/facets/math/asech.rb +8 -0
- data/lib/more/facets/math/atkinson_index.rb +16 -0
- data/lib/more/facets/math/beta.rb +9 -0
- data/lib/more/facets/math/cdf.rb +10 -0
- data/lib/more/facets/math/ceil.rb +8 -0
- data/lib/more/facets/math/cot.rb +8 -0
- data/lib/more/facets/math/coth.rb +8 -0
- data/lib/more/facets/math/csc.rb +8 -0
- data/lib/more/facets/math/csch.rb +8 -0
- data/lib/more/facets/math/delta.rb +8 -0
- data/lib/more/facets/math/epsilon.rb +21 -0
- data/lib/more/facets/math/exp10.rb +8 -0
- data/lib/more/facets/math/exp2.rb +8 -0
- data/lib/more/facets/math/factorial.rb +37 -0
- data/lib/more/facets/math/floor.rb +8 -0
- data/lib/more/facets/math/gamma.rb +12 -0
- data/lib/more/facets/math/gcd.rb +23 -0
- data/lib/more/facets/math/gini_coefficient.rb +33 -0
- data/lib/more/facets/math/kldivergence.rb +19 -0
- data/lib/more/facets/math/lcm.rb +15 -0
- data/lib/more/facets/math/lgamma.rb +21 -0
- data/lib/more/facets/math/linsolve.rb +10 -0
- data/lib/more/facets/math/log2.rb +14 -0
- data/lib/more/facets/math/max.rb +1 -0
- data/lib/more/facets/math/mean.rb +16 -0
- data/lib/more/facets/math/median.rb +15 -0
- data/lib/more/facets/math/min.rb +35 -0
- data/lib/more/facets/math/pow.rb +8 -0
- data/lib/more/facets/math/pstd.rb +1 -0
- data/lib/more/facets/math/pvariance.rb +1 -0
- data/lib/more/facets/math/rmd.rb +16 -0
- data/lib/more/facets/math/root.rb +8 -0
- data/lib/more/facets/math/sec.rb +8 -0
- data/lib/more/facets/math/sech.rb +8 -0
- data/lib/more/facets/math/sign.rb +9 -0
- data/lib/more/facets/math/sinc.rb +8 -0
- data/lib/more/facets/math/sqr.rb +8 -0
- data/lib/more/facets/math/sqsolve.rb +53 -0
- data/lib/more/facets/math/std.rb +27 -0
- data/lib/more/facets/math/stderr.rb +1 -0
- data/lib/more/facets/math/sum.rb +16 -0
- data/lib/more/facets/math/summed_sqdevs.rb +14 -0
- data/lib/more/facets/math/theil_index.rb +24 -0
- data/lib/more/facets/math/variance.rb +31 -0
- data/lib/more/facets/thread.rb +24 -0
- data/lib/tour/facets/array/op_pow.rb +5 -0
- data/lib/tour/facets/module/enclosure.rb +15 -1
- data/lib/tour/facets/module/preextend.rb +26 -0
- data/lib/tour/facets/module/prepend.rb +39 -13
- data/meta/gemfile +1 -1
- data/qed/core/binding/caller.rdoc +1 -3
- data/test/core/array/test_after.rb +1 -1
- data/test/core/array/test_before.rb +1 -1
- data/test/core/array/test_conjoin.rb +1 -1
- data/test/core/array/test_store.rb +1 -1
- data/test/core/hash/test_argumentize.rb +1 -1
- data/test/core/hash/test_join.rb +1 -1
- data/test/core/kernel/test_dup.rb +1 -1
- data/test/core/kernel/test_get.rb +1 -1
- data/test/core/kernel/test_qua_class.rb +1 -1
- data/test/core/time/test_ago.rb +5 -117
- data/test/core/time/test_hence.rb +2 -2
- data/test/core/time/test_in.rb +4 -115
- data/test/core/time/test_less.rb +137 -0
- data/test/core/time/test_set.rb +1 -1
- data/test/core/time/test_shift.rb +126 -0
- data/test/more/test_date.rb +1 -1
- data/test/tour/module/test_cattr.rb +1 -1
- data/test/tour/module/test_class_extend.rb +1 -1
- data/test/tour/module/test_instance_function.rb +1 -1
- data/test/tour/module/test_method_space.rb +1 -1
- metadata +76 -10
- data/lib/core/facets/hash/zipnew.rb +0 -18
- data/lib/core/facets/kernel/clone.rb +0 -1
- data/lib/core/facets/kernel/dup.rb +0 -34
- data/lib/core/facets/kernel/replace.rb +0 -1
@@ -1,25 +1,51 @@
|
|
1
|
+
module Prependable
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend Self
|
5
|
+
base.instance_methods(false).each do |meth|
|
6
|
+
base.method_added(meth)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Self
|
11
|
+
def prepend_module
|
12
|
+
@_prepend_module ||= Module.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_added(meth)
|
16
|
+
return if meth.to_s[-2,2] == ':-'
|
17
|
+
alias_method "#{meth}:-", meth
|
18
|
+
remove_method(meth)
|
19
|
+
prepend_module.module_eval %{
|
20
|
+
def #{meth}(*a,&b); __send__("#{meth}:-",*a,&b); end
|
21
|
+
}
|
22
|
+
include prepend_module
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
1
28
|
class Module
|
2
29
|
|
3
|
-
# Prepend
|
4
|
-
# This only works at the module level.
|
30
|
+
# Prepend module.
|
5
31
|
#
|
6
|
-
#
|
7
|
-
# def
|
32
|
+
# class X
|
33
|
+
# def a; "Xa"; end
|
8
34
|
# end
|
9
35
|
#
|
10
|
-
# module
|
11
|
-
# def
|
36
|
+
# module M
|
37
|
+
# def a; "M" + super ; end
|
12
38
|
# end
|
13
39
|
#
|
14
|
-
#
|
40
|
+
# class X
|
41
|
+
# prepend M
|
42
|
+
# end
|
15
43
|
#
|
16
|
-
#
|
44
|
+
# X.new.a #=> MXa
|
17
45
|
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
aspect.__send__(:include, self)
|
22
|
-
extend aspect
|
46
|
+
def prepend(mod)
|
47
|
+
include Prependable
|
48
|
+
include mod
|
23
49
|
end
|
24
50
|
|
25
51
|
end
|
data/meta/gemfile
CHANGED
data/test/core/hash/test_join.rb
CHANGED
data/test/core/time/test_ago.rb
CHANGED
@@ -1,127 +1,15 @@
|
|
1
1
|
covers 'facets/time/ago'
|
2
2
|
|
3
|
-
|
3
|
+
tests Time do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
5
|
+
# We do not need to test #ago b/c it is an alias for #less.
|
6
|
+
# One test is provided to add to coverage report.
|
8
7
|
|
9
|
-
unit :ago =>
|
8
|
+
unit :ago => "is an alias of #less" do
|
9
|
+
t = Time.utc(2010,01,20,12,00,00)
|
10
10
|
t.ago(1, :year).year.assert = 2009
|
11
11
|
t.ago(2, :years).year.assert = 2008
|
12
12
|
end
|
13
13
|
|
14
|
-
unit :ago => 'weeks' do |t|
|
15
|
-
t.ago(1, :week).day.assert == 13
|
16
|
-
t.ago(2, :weeks).day.assert == 6
|
17
|
-
end
|
18
|
-
|
19
|
-
unit :ago => 'days' do |t|
|
20
|
-
t.ago(1, :day).day.assert == 19
|
21
|
-
t.ago(2, :days).day.assert == 18
|
22
|
-
end
|
23
|
-
|
24
|
-
unit :ago => 'hours' do |t|
|
25
|
-
t.ago(1, :hour).hour.assert == 11
|
26
|
-
t.ago(2, :hours).hour.assert == 10
|
27
|
-
t.ago(12, :hours).hour.assert == 0
|
28
|
-
end
|
29
|
-
|
30
|
-
unit :ago => 'minutes' do |t|
|
31
|
-
t.ago(1, :minute).min.assert == 59
|
32
|
-
t.ago(2, :minutes).min.assert == 58
|
33
|
-
t.ago(60, :minutes).min.assert == 0
|
34
|
-
end
|
35
|
-
|
36
|
-
unit :ago => 'seconds' do |t|
|
37
|
-
t.ago(1, :second).sec.assert == 59
|
38
|
-
t.ago(2, :seconds).sec.assert == 58
|
39
|
-
t.ago(60, :seconds).sec.assert == 0
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
|
44
|
-
unit :ago => "change years" do
|
45
|
-
e = Time.utc(2007,11, 1, 18,30,57)
|
46
|
-
r = Time.utc(2008,11, 1, 18,30,57).ago(1, :years)
|
47
|
-
r.assert == e
|
48
|
-
end
|
49
|
-
|
50
|
-
unit :ago => "change weeks" do
|
51
|
-
e = Time.utc(2008,11,24, 18,30,57)
|
52
|
-
r = Time.utc(2008,12, 1, 18,30,57).ago(1, :weeks)
|
53
|
-
r.assert == e
|
54
|
-
end
|
55
|
-
|
56
|
-
unit :ago => "change days" do
|
57
|
-
e = Time.utc(2008,11,30, 18,30,57)
|
58
|
-
r = Time.utc(2008,12, 1, 18,30,57).ago(1, :days)
|
59
|
-
r.assert == e
|
60
|
-
end
|
61
|
-
|
62
|
-
unit :ago => "change hours" do
|
63
|
-
e = Time.utc(2008,11,30, 23,30,57)
|
64
|
-
r = Time.utc(2008,12, 1, 0,30,57).ago(1, :hours)
|
65
|
-
r.assert == e
|
66
|
-
end
|
67
|
-
|
68
|
-
unit :ago => "change minutes" do
|
69
|
-
e = Time.utc(2008,11,30, 23,58,57)
|
70
|
-
r = Time.utc(2008,12, 1, 0, 0,57).ago(2, :minutes)
|
71
|
-
r.assert == e
|
72
|
-
end
|
73
|
-
|
74
|
-
unit :ago => "change seconds" do
|
75
|
-
e = Time.utc(2008,11,30, 23,59,57)
|
76
|
-
r = Time.utc(2008,12, 1, 0, 0, 1).ago(4, :seconds)
|
77
|
-
r.assert == e
|
78
|
-
end
|
79
|
-
|
80
|
-
context "Months are the tricky one, so they get their own section"
|
81
|
-
|
82
|
-
unit :ago => "change month no year wrap" do
|
83
|
-
e = Time.utc(2008,11, 1)
|
84
|
-
r = Time.utc(2008,12, 1).ago(1, :months)
|
85
|
-
r.assert == e
|
86
|
-
end
|
87
|
-
|
88
|
-
unit :ago => "change month with year wrap due to month" do
|
89
|
-
e = Time.utc(2007,12, 1)
|
90
|
-
r = Time.utc(2008, 1, 1).ago(1, :months)
|
91
|
-
r.assert == e
|
92
|
-
end
|
93
|
-
|
94
|
-
unit :ago => "change month with 12 or more converts extra months into a year adjustment" do
|
95
|
-
e = Time.utc(2007, 1, 1)
|
96
|
-
r = Time.utc(2008, 1, 1).ago(12, :months)
|
97
|
-
r.assert == e
|
98
|
-
|
99
|
-
e = Time.utc(2006,11, 1)
|
100
|
-
r = Time.utc(2008,12, 1).ago(25, :months)
|
101
|
-
r.assert == e
|
102
|
-
end
|
103
|
-
|
104
|
-
# 13 months = 1 year + 1 month AND month changing from 12 to 1 when going backward means go back 1 extra year
|
105
|
-
unit :ago => "change month with 12 or more AND year wrap due to month" do
|
106
|
-
e = Time.utc(2006,12, 1)
|
107
|
-
r = Time.utc(2008, 1, 1).ago(13, :months)
|
108
|
-
r.assert == e
|
109
|
-
end
|
110
|
-
|
111
|
-
unit :ago => "smaller units should remain unchanged" do
|
112
|
-
e = Time.utc(2005, 8,20, 15,37,59)
|
113
|
-
r = Time.utc(2006, 1,20, 15,37,59).ago(5, :months)
|
114
|
-
r.assert == e
|
115
|
-
end
|
116
|
-
|
117
|
-
unit :ago => "passing a negative number to ago should be same as a positive number to hence" do
|
118
|
-
e = Time.utc(2008, 1, 1)
|
119
|
-
r = Time.utc(2006,12, 1).ago(-13, :months)
|
120
|
-
r.assert == e
|
121
|
-
|
122
|
-
r = Time.utc(2006,12, 1).hence(13, :months)
|
123
|
-
r.assert == e
|
124
|
-
end
|
125
|
-
|
126
14
|
end
|
127
15
|
|
@@ -2,8 +2,8 @@ covers 'facets/time/hence'
|
|
2
2
|
|
3
3
|
tests Time do
|
4
4
|
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# We do not need to test #hence b/c it is an alias for #shift.
|
6
|
+
# One test is provided to add to coverage report.
|
7
7
|
|
8
8
|
unit :hence do
|
9
9
|
e = Time.utc(2008,11, 1, 18,30,57)
|
data/test/core/time/test_in.rb
CHANGED
@@ -1,126 +1,15 @@
|
|
1
|
-
covers 'facets/time/
|
1
|
+
covers 'facets/time/ago'
|
2
2
|
|
3
3
|
tests Time do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
unit :in => 'years' do |t|
|
10
|
-
t.in(1, :year).year.assert = 2011
|
11
|
-
t.in(2, :years).year.assert = 2012
|
12
|
-
end
|
13
|
-
|
14
|
-
unit :in => 'weeks' do |t|
|
15
|
-
t.in(1, :week).day.assert == 8
|
16
|
-
t.in(2, :weeks).day.assert == 15
|
17
|
-
end
|
18
|
-
|
19
|
-
unit :in => 'days' do |t|
|
20
|
-
t.in(1, :day).day.assert == 2
|
21
|
-
t.in(2, :days).day.assert == 3
|
22
|
-
end
|
23
|
-
|
24
|
-
unit :in => 'hours' do |t|
|
25
|
-
t.in(1, :hour).hour.assert == 13
|
26
|
-
t.in(2, :hours).hour.assert == 14
|
27
|
-
t.in(12, :hours).hour.assert == 0
|
28
|
-
end
|
29
|
-
|
30
|
-
unit :in => 'minutes' do |t|
|
31
|
-
t.in(1, :minute).min.assert == 1
|
32
|
-
t.in(2, :minutes).min.assert == 2
|
33
|
-
t.in(60, :minutes).min.assert == 0
|
34
|
-
end
|
35
|
-
|
36
|
-
unit :in => 'seconds' do |t|
|
37
|
-
t.in(1, :second).sec.assert == 1
|
38
|
-
t.in(2, :seconds).sec.assert == 2
|
39
|
-
t.in(60, :seconds).sec.assert == 0
|
40
|
-
end
|
5
|
+
# We do not need to test #in b/c it is an alias for #shift.
|
6
|
+
# One test is provided to add to coverage report.
|
41
7
|
|
42
|
-
|
43
|
-
unit :in => "change_years" do
|
8
|
+
unit :in do
|
44
9
|
e = Time.utc(2008,11, 1, 18,30,57)
|
45
10
|
r = Time.utc(2007,11, 1, 18,30,57).in(1, :years)
|
46
11
|
r.assert == e
|
47
12
|
end
|
48
13
|
|
49
|
-
unit :in => "change weeks" do
|
50
|
-
e = Time.utc(2008,12, 1, 18,30,57)
|
51
|
-
r = Time.utc(2008,11,24, 18,30,57).in(1, :weeks)
|
52
|
-
r.assert == e
|
53
|
-
end
|
54
|
-
|
55
|
-
unit :in => "change days" do
|
56
|
-
e = Time.utc(2008,12, 1, 18,30,57)
|
57
|
-
r = Time.utc(2008,11,30, 18,30,57).in(1, :days)
|
58
|
-
r.assert == e
|
59
|
-
end
|
60
|
-
|
61
|
-
unit :in => "change hours" do
|
62
|
-
e = Time.utc(2008,12, 1, 0,30,57)
|
63
|
-
r = Time.utc(2008,11,30, 23,30,57).in(1, :hours)
|
64
|
-
r.assert == e
|
65
|
-
end
|
66
|
-
|
67
|
-
unit :in => "change minutes" do
|
68
|
-
e = Time.utc(2008,12, 1, 0, 0,57)
|
69
|
-
r = Time.utc(2008,11,30, 23,58,57).in(2, :minutes)
|
70
|
-
r.assert == e
|
71
|
-
end
|
72
|
-
|
73
|
-
unit :in => "change seconds" do
|
74
|
-
e = Time.utc(2008,12, 1, 0, 0, 1)
|
75
|
-
r = Time.utc(2008,11,30, 23,59,57).in(4, :seconds)
|
76
|
-
r.assert == e
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
concern "months are more difficult, so they get their own section"
|
81
|
-
|
82
|
-
unit :in => "change month no year wrap" do
|
83
|
-
e = Time.utc(2008,12, 1)
|
84
|
-
r = Time.utc(2008,11, 1).in(1, :months)
|
85
|
-
r.assert == e
|
86
|
-
end
|
87
|
-
|
88
|
-
unit :in => "change month with year wrap due to month" do
|
89
|
-
e = Time.utc(2008, 1, 1)
|
90
|
-
r = Time.utc(2007,12, 1).in(1, :months)
|
91
|
-
r.assert == e
|
92
|
-
end
|
93
|
-
|
94
|
-
unit :in => "change month with 12 or more converts extra months into a year adjustment" do
|
95
|
-
e = Time.utc(2008, 1, 1)
|
96
|
-
r = Time.utc(2007, 1, 1).in(12, :months)
|
97
|
-
r.assert == e
|
98
|
-
|
99
|
-
e = Time.utc(2008,12, 1)
|
100
|
-
r = Time.utc(2006,11, 1).in(25, :months)
|
101
|
-
r.assert == e
|
102
|
-
end
|
103
|
-
|
104
|
-
unit :in => "change month with 12 or more AND year wrap due to month" do
|
105
|
-
e = Time.utc(2008, 1, 1)
|
106
|
-
r = Time.utc(2006,12, 1).in(13, :months)
|
107
|
-
r.assert == e
|
108
|
-
end
|
109
|
-
|
110
|
-
unit :in => "smaller units should remain unchanged" do
|
111
|
-
e = Time.utc(2006, 1,20, 15,37,59)
|
112
|
-
r = Time.utc(2005, 8,20, 15,37,59).in(5, :months)
|
113
|
-
r.assert == e
|
114
|
-
end
|
115
|
-
|
116
|
-
unit :in => "passing a negative number to #in should be same as a positive number to #ago" do
|
117
|
-
e = Time.utc(2005, 8,20)
|
118
|
-
r = Time.utc(2006, 1,20).in(-5, :months)
|
119
|
-
r.assert == e
|
120
|
-
|
121
|
-
r = Time.utc(2006, 1,20).ago(5, :months)
|
122
|
-
r.assert == e
|
123
|
-
end
|
124
|
-
|
125
14
|
end
|
126
15
|
|