jiff 0.0.1 → 0.0.2

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: 951d699915d4ea5e0d75788428898e3a89a19c36
4
- data.tar.gz: 24a37e3f47cff1c38493ca5642925916bfec0570
3
+ metadata.gz: d586cd0f39f9d3f7d0ea94263e0414bfd3c0c114
4
+ data.tar.gz: db6a94b200613fad4dee1118a4920c49921a7207
5
5
  SHA512:
6
- metadata.gz: 987ca0406640756887c757990b1e761c07dc0a89622200c10b92bc093c63487c631a8794ef9b59d67013789e20be395022613d056815850450c9c14b0b061972
7
- data.tar.gz: 77db212d00f873e8d6f471dd51ee4cd5657365505ade0669bc7cab9baa0256b9f752e69ad785322baafa98f925fa875debdaf2367b8918cc9b39a1da9336cca9
6
+ metadata.gz: 0b30baba9c2fe8e47b037b14e8be67a006444e6dd9c50763fa1669b832d11ab3aeb1adb9f6eee2e3c9eaccd330001a8c6851ac51be8f69b033babcd2eece43dd
7
+ data.tar.gz: 6966466c95a8d743e02202c5a4c0baf05e06ca36166c833a8c5b79d6b2640524e5c9806fb6cd03d5749bc421f5e776d3a0870024740053d950f4bed2f44b7e75
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Jiff
2
2
 
3
- [![Build Status](https://travis-ci.org/revett/jiff.svg?branch=master)](https://travis-ci.org/revett/jiff)
3
+ [![Gem Version](https://badge.fury.io/rb/jiff.svg)](http://badge.fury.io/rb/jiff) [![Build Status](https://travis-ci.org/revett/jiff.svg?branch=master)](https://travis-ci.org/revett/jiff) ![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)
4
4
 
5
5
  Parse, validate, manipulate, and display dates in Ruby.
6
6
 
@@ -176,16 +176,16 @@ This is exactly the same as **.add**, only instead of adding time, it subtracts
176
176
 
177
177
  #### Keys
178
178
 
179
- |**Key**|**Description**|
179
+ |**Shorthand**|**Key**|
180
180
  |-------|---------------|
181
- |y |Year |
182
- |M |Month |
183
- |w |Week |
184
- |d |Day |
185
- |h |Hour |
186
- |m |Minute |
187
- |s |Second |
188
- |ms |Millisecond |
181
+ |y |year |
182
+ |M |month |
183
+ |w |week |
184
+ |d |day |
185
+ |h |hour |
186
+ |m |minute |
187
+ |s |second |
188
+ |ms |millisecond |
189
189
 
190
190
  ### Timezone
191
191
 
@@ -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.1'
7
+ spec.version = '0.0.2'
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.}
@@ -1,25 +1,35 @@
1
1
  module Manipulate
2
2
  def add(amount, type)
3
- manipulate(amount, type.to_sym, '+')
3
+ manipulate(amount, convert_type(type), '+')
4
4
  end
5
5
 
6
6
  def subtract(amount, type)
7
- manipulate(amount, type.to_sym, '-')
7
+ manipulate(amount, convert_type(type), '-')
8
8
  end
9
9
 
10
10
  private
11
11
 
12
12
  SECONDS = {
13
- y: 31556926,
14
- M: 2629743.83,
15
- w: 604800,
16
- d: 86400,
17
- h: 3600,
18
- m: 60,
19
- s: 1,
20
- ms: 0.001
13
+ 'y' => 31556926,
14
+ 'M' => 2629743.83,
15
+ 'w' => 604800,
16
+ 'd' => 86400,
17
+ 'h' => 3600,
18
+ 'm' => 60,
19
+ 's' => 1,
20
+ 'ms' => 0.001
21
21
  }
22
22
 
23
+ def convert_type(type)
24
+ return type if type.length <= 2
25
+ %w(month millisecond).include?(type) ? handle_special_type(type)
26
+ : type.downcase[0]
27
+ end
28
+
29
+ def handle_special_type(type)
30
+ type == 'month' ? 'M' : 'ms'
31
+ end
32
+
23
33
  def manipulate(amount, type, operator)
24
34
  raise ArgumentError, 'Invalid Type' unless type_exist? type
25
35
  @date = @date.send(operator, (amount * SECONDS[type]))
@@ -13,34 +13,42 @@ describe Jiff do
13
13
  context 'using a valid type' do
14
14
  context 'adding 1 year' do
15
15
  specify { expect(subject.add(1, 'y').year).to eq 1993 }
16
+ specify { expect(subject.add(1, 'year').year).to eq 1993 }
16
17
  end
17
18
 
18
19
  context 'adding 1 month' do
19
20
  specify { expect(subject.add(1, 'M').month).to eq 7 }
21
+ specify { expect(subject.add(1, 'month').month).to eq 7 }
20
22
  end
21
23
 
22
24
  context 'adding 1 week' do
23
25
  specify { expect(subject.add(1, 'w').day).to eq 15 }
26
+ specify { expect(subject.add(1, 'week').day).to eq 15 }
24
27
  end
25
28
 
26
29
  context 'adding 1 day' do
27
30
  specify { expect(subject.add(1, 'd').day).to eq 9 }
31
+ specify { expect(subject.add(1, 'day').day).to eq 9 }
28
32
  end
29
33
 
30
34
  context 'adding 1 hour' do
31
35
  specify { expect(subject.add(1, 'h').hour).to eq 11 }
36
+ specify { expect(subject.add(1, 'hour').hour).to eq 11 }
32
37
  end
33
38
 
34
39
  context 'adding 1 minute' do
35
40
  specify { expect(subject.add(1, 'm').minute).to eq 31 }
41
+ specify { expect(subject.add(1, 'minute').minute).to eq 31 }
36
42
  end
37
43
 
38
44
  context 'adding 1 second' do
39
45
  specify { expect(subject.add(1, 's').second).to eq 16 }
46
+ specify { expect(subject.add(1, 'second').second).to eq 16 }
40
47
  end
41
48
 
42
49
  context 'adding 1 millisecond' do
43
50
  specify { expect(subject.add(1, 'ms').millisecond).to eq 1 }
51
+ specify { expect(subject.add(1, 'millisecond').millisecond).to eq 1 }
44
52
  end
45
53
  end
46
54
 
@@ -55,34 +63,42 @@ describe Jiff do
55
63
  context 'using a valid type' do
56
64
  context 'subtracting 1 year' do
57
65
  specify { expect(subject.subtract(1, 'y').year).to eq 1991 }
66
+ specify { expect(subject.subtract(1, 'year').year).to eq 1991 }
58
67
  end
59
68
 
60
69
  context 'subtracting 1 month' do
61
70
  specify { expect(subject.subtract(1, 'M').month).to eq 5 }
71
+ specify { expect(subject.subtract(1, 'month').month).to eq 5 }
62
72
  end
63
73
 
64
74
  context 'subtracting 1 week' do
65
75
  specify { expect(subject.subtract(1, 'w').day).to eq 1 }
76
+ specify { expect(subject.subtract(1, 'week').day).to eq 1 }
66
77
  end
67
78
 
68
79
  context 'subtracting 1 day' do
69
80
  specify { expect(subject.subtract(1, 'd').day).to eq 7 }
81
+ specify { expect(subject.subtract(1, 'day').day).to eq 7 }
70
82
  end
71
83
 
72
84
  context 'subtracting 1 hour' do
73
85
  specify { expect(subject.subtract(1, 'h').hour).to eq 9 }
86
+ specify { expect(subject.subtract(1, 'hour').hour).to eq 9 }
74
87
  end
75
88
 
76
89
  context 'subtracting 1 minute' do
77
90
  specify { expect(subject.subtract(1, 'm').minute).to eq 29 }
91
+ specify { expect(subject.subtract(1, 'minute').minute).to eq 29 }
78
92
  end
79
93
 
80
94
  context 'subtracting 1 second' do
81
95
  specify { expect(subject.subtract(1, 's').second).to eq 14 }
96
+ specify { expect(subject.subtract(1, 'second').second).to eq 14 }
82
97
  end
83
98
 
84
99
  context 'subtracting 1 millisecond' do
85
100
  specify { expect(subject.subtract(1, 'ms').millisecond).to eq 998 }
101
+ specify { expect(subject.subtract(1, 'millisecond').millisecond).to eq 998 }
86
102
  end
87
103
  end
88
104
 
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.1
4
+ version: 0.0.2
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-25 00:00:00.000000000 Z
11
+ date: 2014-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler