richunits 0.2.0 → 0.5.0

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.
@@ -1,53 +0,0 @@
1
- # = Weekdays
2
- #
3
- # The Weekdays class provides useful weekday terminology.
4
-
5
- class Weekdays
6
-
7
- WEEKDAYS = 1..5 # Monday is wday 1
8
- ONE_DAY = 60 * 60 * 24
9
-
10
- def initialize(n)
11
- @n = n
12
- end
13
-
14
- def ago(time = ::Time.now)
15
- step :down, time
16
- end
17
- alias_method :until, :ago
18
- alias_method :before, :ago
19
-
20
- def since(time = ::Time.now)
21
- step :up, time
22
- end
23
- alias_method :from_now, :since
24
- alias_method :after, :since
25
-
26
- private
27
-
28
- def step(direction, original_time)
29
- result = original_time
30
- time = ONE_DAY
31
-
32
- compare = direction == :up ? ">" : "<"
33
- time *= -1 if direction == :down
34
-
35
- @n.times do
36
- result += time until result.send(compare, original_time) && WEEKDAYS.member?(result.wday)
37
- original_time = result
38
- end
39
- result
40
- end
41
- end
42
-
43
- class Numeric
44
-
45
- # Works with day in terms of weekdays.
46
- def weekdays
47
- Weekdays.new(self)
48
- end
49
-
50
- alias_method :weekday, :weekdays
51
-
52
- end
53
-