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.
- data/CHANGES +17 -1
- data/COPYING +22 -0
- data/MANIFEST +29 -13
- data/README +50 -1
- data/RELEASE +21 -0
- data/TODO +5 -0
- data/VERSION +1 -1
- data/doc/ads/rdoc.html +12 -0
- data/doc/images/ruby-md.png +0 -0
- data/doc/images/ruby-sm.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tiger-sm.png +0 -0
- data/doc/images/tiger_logo.png +0 -0
- data/doc/index.css +179 -0
- data/doc/index.html +163 -0
- data/lib/rich_units.rb +1 -4
- data/lib/richunits.rb +5 -0
- data/lib/richunits/bytes.rb +178 -0
- data/lib/richunits/duration.rb +290 -0
- data/lib/richunits/multipliers.rb +113 -0
- data/lib/richunits/times.rb +491 -0
- data/lib/richunits/weekdays.rb +65 -0
- data/meta/version +1 -0
- data/test/test_bytes.rb +1 -1
- data/test/test_duration.rb +54 -0
- data/test/test_multipliers.rb +1 -1
- data/test/test_times.rb +10 -9
- metadata +38 -23
- data/NEWS +0 -3
- data/lib/rich_units/bytes.rb +0 -164
- data/lib/rich_units/multipliers.rb +0 -99
- data/lib/rich_units/times.rb +0 -388
- data/lib/rich_units/weekdays.rb +0 -53
data/lib/rich_units/weekdays.rb
DELETED
@@ -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
|
-
|