fat_core 0.2.7 → 0.2.8
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 +19 -0
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/period_spec.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5ed9e5648eeb55ee7853b351b5f2f9fa3cb2b4e
|
4
|
+
data.tar.gz: 8b2cf74d3c6cb40a6adae6ed48fd4077da877e00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d9379cabd3a65bc7db3260d467d86edf7c7288ba09bb343cbe2024e67b7d1b0bb6b50e7ca5bed5fe3e90d41e7c9a31c757a3ac4cecdbaeeb98c5da73cb71cd4
|
7
|
+
data.tar.gz: aeddbd7df46977a283259415bc3e2739d82280e19fe1380886dad050e888c3e9e3dd349a45b3c64f67201f03f77007b8bdd9a352a2eb0d8cc220675e8502a006
|
data/lib/fat_core/period.rb
CHANGED
@@ -100,6 +100,25 @@ class Period
|
|
100
100
|
self.contains?(date)
|
101
101
|
end
|
102
102
|
|
103
|
+
# Return the number of days in the period
|
104
|
+
def days
|
105
|
+
last - first + 1
|
106
|
+
end
|
107
|
+
|
108
|
+
# Return the fractional number of months in the period. By default, use the
|
109
|
+
# average number of days in a month, but allow the user to override the
|
110
|
+
# assumption with a parameter.
|
111
|
+
def months(days_in_month = 30.436875)
|
112
|
+
(days / days_in_month).to_f
|
113
|
+
end
|
114
|
+
|
115
|
+
# Return the fractional number of years in the period. By default, use the
|
116
|
+
# average number of days in a year, but allow the user to override the
|
117
|
+
# assumption with a parameter.
|
118
|
+
def years(days_in_year = 365.2425)
|
119
|
+
(days / days_in_year).to_f
|
120
|
+
end
|
121
|
+
|
103
122
|
def trading_days
|
104
123
|
select(&:nyse_workday?)
|
105
124
|
end
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/period_spec.rb
CHANGED
@@ -199,6 +199,24 @@ describe Period do
|
|
199
199
|
expect(pp === Date.parse('2012-07-04')).to be false
|
200
200
|
end
|
201
201
|
|
202
|
+
it "should be able to convert itself to days" do
|
203
|
+
expect(Period.new('2013-01-01', '2013-01-01').days).to eq(1)
|
204
|
+
expect(Period.new('2013-01-01', '2013-12-31').days).to eq(365)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should be able to convert itself to fractional months" do
|
208
|
+
expect(Period.new('2013-01-01', '2013-01-01').months).to eq(1/30.436875)
|
209
|
+
expect(Period.new('2013-01-01', '2013-12-31').months(30)).
|
210
|
+
to eq(365 / 30.0)
|
211
|
+
expect(Period.new('2013-01-01', '2013-06-30').months.round(0)).to eq(6.0)
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should be able to convert itself to fractional years" do
|
215
|
+
expect(Period.new('2013-01-01', '2013-01-01').years).to eq(1/365.2425)
|
216
|
+
expect(Period.new('2013-01-01', '2013-12-31').years(365)).to eq(1.0)
|
217
|
+
expect(Period.new('2013-01-01', '2013-06-30').years.round(1)).to eq(0.5)
|
218
|
+
end
|
219
|
+
|
202
220
|
it "should be able to enumerate its days" do
|
203
221
|
Period.parse_spec('2014-12').each do |dy|
|
204
222
|
expect(dy.class).to eq Date
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel E. Doherty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|