fat_core 0.4.2 → 0.5.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.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +6 -0
- data/Rakefile +8 -0
- data/fat_core.gemspec +2 -2
- data/lib/fat_core/date.rb +0 -1
- data/lib/fat_core/enumerable.rb +1 -1
- data/lib/fat_core/period.rb +30 -0
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/kernel_spec.rb +1 -0
- data/spec/lib/period_spec.rb +41 -2
- data/spec/spec_helper.rb +2 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdaf3715eeb1419b1926b013d783c344de551510
|
4
|
+
data.tar.gz: 7f356adfefc210d1f5455b1ab9dac4e190f9697f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02669fb5def651019c5673ae5ca6d532193db6e03054b94055dc324181a7e0d9f8ce2669c485d1f692667406c83908f9ba95764637806bff6bb1adbcb94d2a72
|
7
|
+
data.tar.gz: 64b998e157700080144adc6b882c3cea0acd5949fa38dda836dd9158eddc7da8077b9df3d77f111e59a3c54cec67151fa097b4a182f26e95bb7fca33c879d2ff
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--color
|
2
|
-
--format
|
2
|
+
--format documentation
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/fat_core.gemspec
CHANGED
@@ -23,10 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.5"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "rspec"
|
26
|
-
spec.add_development_dependency "rcodetools"
|
27
26
|
spec.add_development_dependency "byebug"
|
28
27
|
spec.add_development_dependency "pry"
|
29
|
-
spec.add_development_dependency "pry-
|
28
|
+
spec.add_development_dependency "pry-byebug"
|
29
|
+
spec.add_development_dependency "rcodetools"
|
30
30
|
|
31
31
|
spec.add_runtime_dependency "activesupport"
|
32
32
|
spec.add_runtime_dependency "erubis"
|
data/lib/fat_core/date.rb
CHANGED
data/lib/fat_core/enumerable.rb
CHANGED
data/lib/fat_core/period.rb
CHANGED
@@ -133,6 +133,36 @@ class Period
|
|
133
133
|
Period.new(Date.parse_spec(from, :from), Date.parse_spec(to, :to))
|
134
134
|
end
|
135
135
|
|
136
|
+
def self.parse(spec = nil, default_spec: 'this_year', truncate: false)
|
137
|
+
spec = default_spec if spec.blank?
|
138
|
+
from, to = parse_from_to_spec(spec)
|
139
|
+
to ||= from
|
140
|
+
from ||= to
|
141
|
+
d1 = Date.parse_spec(from, :from) if from
|
142
|
+
d2 = Date.parse_spec(to, :to) if to
|
143
|
+
d1 ||= Date::BOT
|
144
|
+
d2 ||= Date::EOT
|
145
|
+
d2 = Date.current if truncate
|
146
|
+
Period.new(d1, d2)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Extract start and end dates
|
150
|
+
def self.parse_from_to_spec(spec)
|
151
|
+
spec = spec.clean
|
152
|
+
if spec =~ /\Afrom (.*) to (.*)\z/
|
153
|
+
from_spec = $~[1]
|
154
|
+
to_spec = $~[2]
|
155
|
+
elsif spec =~ /\Afrom (.*)\z/
|
156
|
+
from_spec = $~[1]
|
157
|
+
to_spec = nil
|
158
|
+
elsif spec =~ /\Ato (.*)\z/
|
159
|
+
to_spec = $~[1]
|
160
|
+
else
|
161
|
+
to_spec = spec
|
162
|
+
end
|
163
|
+
[from_spec, to_spec]
|
164
|
+
end
|
165
|
+
|
136
166
|
# Possibly useful class method to take an array of periods and join all the
|
137
167
|
# contiguous ones, then return an array of the disjoint periods not
|
138
168
|
# contiguous to one another. An array of periods with no gaps should return
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/kernel_spec.rb
CHANGED
data/spec/lib/period_spec.rb
CHANGED
@@ -42,15 +42,48 @@ describe Period do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
describe "class methods" do
|
45
|
+
it 'should be able to parse a period spec' do
|
46
|
+
pd = Period.parse
|
47
|
+
expect(pd.first).to eq(Date.parse('2012-01-01'))
|
48
|
+
expect(pd.last).to eq(Date.parse('2012-12-31'))
|
45
49
|
|
46
|
-
|
50
|
+
pd = Period.parse('from 2012-07 to 2012')
|
51
|
+
expect(pd.first).to eq(Date.parse('2012-07-01'))
|
52
|
+
expect(pd.last).to eq(Date.parse('2012-12-31'))
|
53
|
+
|
54
|
+
pd = Period.parse('to 2012')
|
55
|
+
expect(pd.first).to eq(Date.parse('2012-01-01'))
|
56
|
+
expect(pd.last).to eq(Date.parse('2012-12-31'))
|
57
|
+
|
58
|
+
pd = Period.parse('from 2012')
|
59
|
+
expect(pd.first).to eq(Date.parse('2012-01-01'))
|
60
|
+
expect(pd.last).to eq(Date.parse('2012-12-31'))
|
61
|
+
|
62
|
+
pd = Period.parse('2012')
|
63
|
+
expect(pd.first).to eq(Date.parse('2012-01-01'))
|
64
|
+
expect(pd.last).to eq(Date.parse('2012-12-31'))
|
65
|
+
|
66
|
+
pd = Period.parse('this_year')
|
67
|
+
expect(pd.first).to eq(Date.parse('2012-01-01'))
|
68
|
+
expect(pd.last).to eq(Date.parse('2012-12-31'))
|
69
|
+
|
70
|
+
pd = Period.parse('from last_year to this_year')
|
71
|
+
expect(pd.first).to eq(Date.parse('2011-01-01'))
|
72
|
+
expect(pd.last).to eq(Date.parse('2012-12-31'))
|
73
|
+
|
74
|
+
pd = Period.parse('from last_year to this_year', truncate: true)
|
75
|
+
expect(pd.first).to eq(Date.parse('2011-01-01'))
|
76
|
+
expect(pd.last).to eq(Date.parse('2012-07-18'))
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should know how to parse a pair of date specs' do
|
47
80
|
expect(Period.parse_spec.first).to eq Date.current
|
48
81
|
expect(Period.parse_spec('2014-3Q').first).to eq Date.parse('2014-07-01')
|
49
82
|
expect(Period.parse_spec('2014-3Q').last).to eq Date.parse('2014-09-30')
|
50
83
|
expect(Period.parse_spec(nil, '2014-3Q').last).to eq Date.parse('2014-09-30')
|
51
84
|
end
|
52
85
|
|
53
|
-
it
|
86
|
+
it 'should know what the valid chunk syms are' do
|
54
87
|
expect(Period.chunk_syms.size).to eq 9
|
55
88
|
end
|
56
89
|
|
@@ -124,6 +157,12 @@ describe Period do
|
|
124
157
|
expect(periods[1].last).to eq(Date.parse('2012-07-31'))
|
125
158
|
expect(periods[2].last).to eq(Date.parse('2012-08-31'))
|
126
159
|
end
|
160
|
+
|
161
|
+
it "should return nil if comparing incomparables" do
|
162
|
+
pd = Period.new('2012-08-01', '2012-08-31')
|
163
|
+
rg = (Date.parse('2012-08-01')..Date.parse('2012-08-31'))
|
164
|
+
expect(pd <=> rg).to be_nil
|
165
|
+
end
|
127
166
|
end
|
128
167
|
|
129
168
|
describe "instance methods" do
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.5.2
|
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-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: byebug
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: pry
|
98
|
+
name: pry-byebug
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rcodetools
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -173,6 +173,8 @@ extra_rdoc_files: []
|
|
173
173
|
files:
|
174
174
|
- ".gitignore"
|
175
175
|
- ".rspec"
|
176
|
+
- ".ruby-version"
|
177
|
+
- ".travis.yml"
|
176
178
|
- ".yardopts"
|
177
179
|
- Gemfile
|
178
180
|
- LICENSE.txt
|
@@ -227,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
229
|
version: '0'
|
228
230
|
requirements: []
|
229
231
|
rubyforge_project:
|
230
|
-
rubygems_version: 2.
|
232
|
+
rubygems_version: 2.4.5
|
231
233
|
signing_key:
|
232
234
|
specification_version: 4
|
233
235
|
summary: fat_core provides some useful core extensions
|
@@ -244,4 +246,3 @@ test_files:
|
|
244
246
|
- spec/lib/string_spec.rb
|
245
247
|
- spec/lib/symbol_spec.rb
|
246
248
|
- spec/spec_helper.rb
|
247
|
-
has_rdoc:
|