fat_core 0.1.2 → 0.1.3
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 +4 -4
- data/lib/fat_core/period.rb +27 -16
- data/lib/fat_core/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf42c04e2df2a194b2c1443f37fa544e67dc4755
|
4
|
+
data.tar.gz: 4479332da5870aad790def2b520cc0054dd66f30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce1c348abc44daae141b687597ee12ce1da0415b2a7da3d5aedbf6ec83fc62f09626912296b5ff05cb188cd42e3622e03cf45c1c0d30b59da76bb0503ad1711a
|
7
|
+
data.tar.gz: 527f34537f750dbcf71764c9e2bf5c80d3f22c2f282fc76b9aac62d4e79d599ca2136a4aaeb8e484d442863a3b4ccc807ab86608c3f8fe72635f0f73cf26bc2c
|
data/lib/fat_core/period.rb
CHANGED
@@ -47,6 +47,33 @@ class Period
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
# Comparable base: periods are equal only if their first and last dates are
|
51
|
+
# equal. Sorting will be by first date, then last, so periods starting on
|
52
|
+
# the same date will sort by last date, thus, from smallest to largest in
|
53
|
+
# size.
|
54
|
+
def <=>(other)
|
55
|
+
[first, last] <=> [other.first, other.last]
|
56
|
+
end
|
57
|
+
|
58
|
+
# Comparable does not include this.
|
59
|
+
def !=(other)
|
60
|
+
!(self == other)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Enumerable base. Yield each day in the period.
|
64
|
+
def each
|
65
|
+
d = first
|
66
|
+
while d <= last
|
67
|
+
yield d
|
68
|
+
d = d + 1.day
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Case equality checks for inclusion of date in period.
|
73
|
+
def ===(date)
|
74
|
+
self.contains?(date)
|
75
|
+
end
|
76
|
+
|
50
77
|
# Return a period based on two date specs (see Date.parse_spec), a '''from'
|
51
78
|
# and a 'to' spec. If the to-spec is not given or is nil, the from-spec is
|
52
79
|
# used for both the from- and to-spec. If no from-spec is given, return
|
@@ -85,14 +112,6 @@ class Period
|
|
85
112
|
# TO_DATE = Period.new(Date::BOT, Date.current)
|
86
113
|
# FOREVER = Period.new(Date::BOT, Date::EOT)
|
87
114
|
|
88
|
-
def each
|
89
|
-
d = first
|
90
|
-
while d <= last
|
91
|
-
yield d
|
92
|
-
d = d + 1.day
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
115
|
def self.chunk_syms
|
97
116
|
[:day, :week, :biweek, :semimonth, :month, :bimonth,
|
98
117
|
:quarter, :year, :irregular]
|
@@ -180,14 +199,6 @@ class Period
|
|
180
199
|
(first..last)
|
181
200
|
end
|
182
201
|
|
183
|
-
def ==(other)
|
184
|
-
first == other.first && last == other.last
|
185
|
-
end
|
186
|
-
|
187
|
-
def <=>(other)
|
188
|
-
[first, size] <=> [other.first, other.size]
|
189
|
-
end
|
190
|
-
|
191
202
|
def to_s
|
192
203
|
if first.beginning_of_year? && last.end_of_year? && first.year == last.year
|
193
204
|
"#{first.year}"
|
data/lib/fat_core/version.rb
CHANGED