jiff 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/jiff.gemspec +1 -1
- data/lib/jiff.rb +7 -2
- data/spec/jiff_spec.rb +17 -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: c4eb447fe9a1cedb307d125b3a539bb4b9531c2a
|
4
|
+
data.tar.gz: 0f512b71e0472e52bd6960692b1efd57f56511cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b1a4823a2c04cf41cdbf740f47bccc402b4fadbd6f122319d450353aac39e51bbd8169676626c2adeb010d25a063fff1839beb92e594b70f8fb48935db263b5
|
7
|
+
data.tar.gz: 5fb29273e843b3ce4425b3e700639fcb7d66c4201c5df5188edf972cc8bdf0bc7c11bf119ec51d0f1c98b01e3ad711f2aef449f59acaa1af733ecd6978ae8ded
|
data/README.md
CHANGED
data/jiff.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "jiff"
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.3'
|
8
8
|
spec.authors = ["Charlie Revett"]
|
9
9
|
spec.email = ["charlierevett@gmail.com"]
|
10
10
|
spec.summary = %q{Parse, validate, manipulate, and display dates in Ruby.}
|
data/lib/jiff.rb
CHANGED
@@ -8,8 +8,8 @@ class Jiff
|
|
8
8
|
|
9
9
|
attr_reader :date
|
10
10
|
|
11
|
-
def initialize
|
12
|
-
@date = Time.new
|
11
|
+
def initialize(query = nil)
|
12
|
+
@date = query.nil? ? Time.new : parse(query)
|
13
13
|
end
|
14
14
|
|
15
15
|
def day
|
@@ -58,6 +58,11 @@ class Jiff
|
|
58
58
|
|
59
59
|
private
|
60
60
|
|
61
|
+
def parse(query)
|
62
|
+
raise ArgumentError, 'Query must be Integer' unless query.is_a? Integer
|
63
|
+
Time.at query
|
64
|
+
end
|
65
|
+
|
61
66
|
def pattern(format, to_int = true)
|
62
67
|
date.strftime(format).tap { |d| return d.to_i if to_int }
|
63
68
|
end
|
data/spec/jiff_spec.rb
CHANGED
@@ -8,6 +8,23 @@ describe Jiff do
|
|
8
8
|
|
9
9
|
after { Timecop.return }
|
10
10
|
|
11
|
+
describe '.new' do
|
12
|
+
context 'with no query string' do
|
13
|
+
specify { expect(subject.date).to eq time }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with a unix timestamp' do
|
17
|
+
let(:timestamp) { 1414612800 }
|
18
|
+
let(:expected) { Time.at timestamp }
|
19
|
+
specify { expect(described_class.new(timestamp).date).to eq expected}
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with a String' do
|
23
|
+
let(:query) { 'batman' }
|
24
|
+
specify { expect{ described_class.new query }.to raise_error ArgumentError }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
11
28
|
describe '#date' do
|
12
29
|
specify { expect(subject.date).to eq time }
|
13
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jiff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Revett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|