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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d586cd0f39f9d3f7d0ea94263e0414bfd3c0c114
4
- data.tar.gz: db6a94b200613fad4dee1118a4920c49921a7207
3
+ metadata.gz: c4eb447fe9a1cedb307d125b3a539bb4b9531c2a
4
+ data.tar.gz: 0f512b71e0472e52bd6960692b1efd57f56511cc
5
5
  SHA512:
6
- metadata.gz: 0b30baba9c2fe8e47b037b14e8be67a006444e6dd9c50763fa1669b832d11ab3aeb1adb9f6eee2e3c9eaccd330001a8c6851ac51be8f69b033babcd2eece43dd
7
- data.tar.gz: 6966466c95a8d743e02202c5a4c0baf05e06ca36166c833a8c5b79d6b2640524e5c9806fb6cd03d5749bc421f5e776d3a0870024740053d950f4bed2f44b7e75
6
+ metadata.gz: 2b1a4823a2c04cf41cdbf740f47bccc402b4fadbd6f122319d450353aac39e51bbd8169676626c2adeb010d25a063fff1839beb92e594b70f8fb48935db263b5
7
+ data.tar.gz: 5fb29273e843b3ce4425b3e700639fcb7d66c4201c5df5188edf972cc8bdf0bc7c11bf119ec51d0f1c98b01e3ad711f2aef449f59acaa1af733ecd6978ae8ded
data/README.md CHANGED
@@ -28,6 +28,12 @@ Create a new **Jiff** set to the current date/time:
28
28
  Jiff.new
29
29
  ```
30
30
 
31
+ Create a new **Jiff** set to an unix timestamp:
32
+
33
+ ```ruby
34
+ Jiff.new 1414612800
35
+ ```
36
+
31
37
  Access the date/time object at any point:
32
38
 
33
39
  ```ruby
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.2'
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.2
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-28 00:00:00.000000000 Z
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler