pigeon_hole 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: 6d01a12f251e39f29b4e12db0d70149bd0b49d4c
4
- data.tar.gz: 092d50e556f776111d5aa7726883a344d61e8b6d
3
+ metadata.gz: badf7d36df8cf48970fff51efb54113da72cfa73
4
+ data.tar.gz: 1a25ea2d30cfd39078f9251557c5f65493d49364
5
5
  SHA512:
6
- metadata.gz: 65d283f300b2a7d8bae948e4fdf547965cd292e6b945ffd17a7ebc9db0dd0f1af29491e4ece99161861b3be610d108343b5df233aa5998b772f4e373715a1c16
7
- data.tar.gz: fd3f11d35299c79dfeffed5b945491cdfeab16a7470be28f394d12179becb2b9f2926e251a1ecaf705fec9c32603d595605baef1040f1ab0f88333da7117ce29
6
+ metadata.gz: eaadcbb4a7f6c1fcb209f092d1aa22d58fad433d9cfe927d6ac55034006ae8e4ef23b10eb05ef358160b26a9781b81d68b02687d8fc04b7265a4b0ee8c3a9a0c
7
+ data.tar.gz: c350244edb364077f23ade4f1a49deeb7e0ab744ba9da321616aeefc54d82b548e31683f5d87b8e6f8dc64da8438138eca31f7d1ef1ee9c9bb750550609af20e
@@ -2,26 +2,17 @@ module PigeonHole
2
2
  class JSONTime < SimpleDelegator
3
3
  # Deserializes JSON string by converting time since epoch to Time
4
4
  def self.json_create(object)
5
- if usec = object.delete('u') # used to be tv_usec -> tv_nsec
6
- object['n'] = usec * 1000
7
- end
8
- if method_defined?(:tv_nsec)
9
- Time.at(object['s'], Time.Rational(object['n'], 1000))
10
- else
11
- Time.at(object['s'], object['n'] / 1000)
12
- end
5
+ ms_since_epoc = object['ms'].to_i
6
+ seconds, fragment = ms_since_epoc.divmod(1000)
7
+ Time.at(seconds, fragment * 1000).utc
13
8
  end
14
9
 
15
10
  # Returns a hash, that will be turned into a JSON object and represent this
16
11
  # object.
17
12
  def as_json(*)
18
- nanoseconds = [ tv_usec * 1000 ]
19
- respond_to?(:tv_nsec) and nanoseconds << tv_nsec
20
- nanoseconds = nanoseconds.max
21
13
  {
22
14
  JSON.create_id => self.class.name,
23
- 's' => tv_sec,
24
- 'n' => nanoseconds,
15
+ 'ms' => (tv_sec * 1000) + (usec / 1000),
25
16
  }
26
17
  end
27
18
 
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe "serializing dates" do
4
+ let(:date) { random_date }
5
+
6
+ subject { PigeonHole.generate(date: date) }
7
+
8
+ it "serializes hash into a string" do
9
+ result = subject
10
+ expect(result).to_not be_empty
11
+ end
12
+
13
+ it "can be deserialized to a date time" do
14
+ result = subject
15
+ hash = PigeonHole.parse(result)
16
+ expect(hash).to eq({ "date" => date })
17
+ expect(hash["date"]).to be_a(Date)
18
+ end
19
+ end
20
+
21
+ describe "serializing times" do
22
+ let(:time) { random_time. }
23
+
24
+ subject { PigeonHole.generate(time: time) }
25
+
26
+ it "serializes hash into a string" do
27
+ result = subject
28
+ expect(result).to_not be_empty
29
+ end
30
+
31
+ it "can be deserialized to a time" do
32
+ result = subject
33
+ hash = PigeonHole.parse(result)
34
+ expect(hash).to eq({ "time" => time })
35
+ expect(hash["time"]).to be_a(Time)
36
+ end
37
+ end
38
+
39
+ describe "serializing datetimes" do
40
+ let(:date_time) { random_date_time }
41
+
42
+ subject { PigeonHole.generate(date_time: date_time) }
43
+
44
+ it "serializes hash into a string" do
45
+ result = subject
46
+ expect(result).to_not be_empty
47
+ end
48
+
49
+ it "can be deserialized to a date_time" do
50
+ result = subject
51
+ hash = PigeonHole.parse(result)
52
+ expect(hash["date_time"]).to be_a(DateTime)
53
+ expect(hash["date_time"].to_date).to eq(date_time.to_date)
54
+ expect(hash["date_time"].to_time.to_i).to eq(date_time.to_time.to_i)
55
+ end
56
+ end
57
+
58
+ describe "serializing symbols" do
59
+ let(:symbol) { :a_symbol }
60
+
61
+ subject { PigeonHole.generate(symbol: symbol) }
62
+
63
+ it "serializes hash into a string" do
64
+ result = subject
65
+ expect(result).to_not be_empty
66
+ end
67
+
68
+ it "can be deserialized to a symbol" do
69
+ result = subject
70
+ hash = PigeonHole.parse(result)
71
+ expect(hash).to eq({ "symbol" => symbol })
72
+ expect(hash["symbol"]).to be_a(Symbol)
73
+ end
74
+ end
75
+
76
+ describe "serializing arrays" do
77
+ let(:array) { [:a_symbol, { "test" => :foo } ] }
78
+
79
+ subject { PigeonHole.generate(array: array) }
80
+
81
+ it "serializes hash into a string" do
82
+ result = subject
83
+ expect(result).to_not be_empty
84
+ end
85
+
86
+ it "can be deserialized to a array" do
87
+ result = subject
88
+ hash = PigeonHole.parse(result)
89
+ expect(hash).to eq({ "array" => array })
90
+ expect(hash["array"]).to be_a(Array)
91
+ end
92
+ end
93
+
94
+ describe "serializing nested hashes" do
95
+ let(:expected) do
96
+ {
97
+ foo: {
98
+ bar: random_time,
99
+ baz: :temp
100
+ }
101
+ }
102
+ end
103
+
104
+ subject { PigeonHole.generate(expected) }
105
+
106
+ it "serializes hash into a string" do
107
+ result = subject
108
+ expect(result).to_not be_empty
109
+ end
110
+
111
+ it "can be deserialized to a symbol" do
112
+ result = subject
113
+ hash = PigeonHole.parse(result)
114
+
115
+ expect(symbolize_hash(hash)).to eq(expected)
116
+ end
117
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe "serializing dates" do
4
+ let(:date) { random_date }
5
+
6
+ subject { PigeonHole.generate(date: date) }
7
+
8
+ it "serializes hash into a string" do
9
+ result = subject
10
+ expect(result).to_not be_empty
11
+ end
12
+
13
+ it "can be deserialized to a date time" do
14
+ result = subject
15
+ hash = PigeonHole.parse(result)
16
+ expect(hash).to eq({ "date" => date })
17
+ expect(hash["date"]).to be_a(Date)
18
+ end
19
+ end
20
+
21
+ describe "serializing times" do
22
+ let(:time) { random_time.u }
23
+
24
+ subject { PigeonHole.generate(time: time) }
25
+
26
+ it "serializes hash into a string" do
27
+ result = subject
28
+ expect(result).to_not be_empty
29
+ end
30
+
31
+ it "can be deserialized to a time" do
32
+ result = subject
33
+ hash = PigeonHole.parse(result)
34
+ expect(hash).to eq({ "time" => time })
35
+ expect(hash["time"]).to be_a(Time)
36
+ end
37
+ end
38
+
39
+ describe "serializing datetimes" do
40
+ let(:date_time) { random_date_time }
41
+
42
+ subject { PigeonHole.generate(date_time: date_time) }
43
+
44
+ it "serializes hash into a string" do
45
+ result = subject
46
+ expect(result).to_not be_empty
47
+ end
48
+
49
+ it "can be deserialized to a date_time" do
50
+ result = subject
51
+ hash = PigeonHole.parse(result)
52
+ expect(hash["date_time"]).to be_a(DateTime)
53
+ expect(hash["date_time"].to_date).to eq(date_time.to_date)
54
+ expect(hash["date_time"].to_time.to_i).to eq(date_time.to_time.to_i)
55
+ end
56
+ end
57
+
58
+ describe "serializing symbols" do
59
+ let(:symbol) { :a_symbol }
60
+
61
+ subject { PigeonHole.generate(symbol: symbol) }
62
+
63
+ it "serializes hash into a string" do
64
+ result = subject
65
+ expect(result).to_not be_empty
66
+ end
67
+
68
+ it "can be deserialized to a symbol" do
69
+ result = subject
70
+ hash = PigeonHole.parse(result)
71
+ expect(hash).to eq({ "symbol" => symbol })
72
+ expect(hash["symbol"]).to be_a(Symbol)
73
+ end
74
+ end
75
+
76
+ describe "serializing arrays" do
77
+ let(:array) { [:a_symbol, { "test" => :foo } ] }
78
+
79
+ subject { PigeonHole.generate(array: array) }
80
+
81
+ it "serializes hash into a string" do
82
+ result = subject
83
+ expect(result).to_not be_empty
84
+ end
85
+
86
+ it "can be deserialized to a array" do
87
+ result = subject
88
+ hash = PigeonHole.parse(result)
89
+ expect(hash).to eq({ "array" => array })
90
+ expect(hash["array"]).to be_a(Array)
91
+ end
92
+ end
93
+
94
+ describe "serializing nested hashes" do
95
+ let(:expected) do
96
+ {
97
+ foo: {
98
+ bar: random_time,
99
+ baz: :temp
100
+ }
101
+ }
102
+ end
103
+
104
+ subject { PigeonHole.generate(expected) }
105
+
106
+ it "serializes hash into a string" do
107
+ result = subject
108
+ expect(result).to_not be_empty
109
+ end
110
+
111
+ it "can be deserialized to a symbol" do
112
+ result = subject
113
+ hash = PigeonHole.parse(result)
114
+
115
+ expect(symbolize_hash(hash)).to eq(expected)
116
+ end
117
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe "serializing dates" do
4
+ let(:date) { random_date }
5
+
6
+ subject { PigeonHole.generate(date: date) }
7
+
8
+ it "serializes hash into a string" do
9
+ result = subject
10
+ expect(result).to_not be_empty
11
+ end
12
+
13
+ it "can be deserialized to a date time" do
14
+ result = subject
15
+ hash = PigeonHole.parse(result)
16
+ expect(hash).to eq({ "date" => date })
17
+ expect(hash["date"]).to be_a(Date)
18
+ end
19
+ end
20
+
21
+ describe "serializing times" do
22
+ let(:time) { random_time.us }
23
+
24
+ subject { PigeonHole.generate(time: time) }
25
+
26
+ it "serializes hash into a string" do
27
+ result = subject
28
+ expect(result).to_not be_empty
29
+ end
30
+
31
+ it "can be deserialized to a time" do
32
+ result = subject
33
+ hash = PigeonHole.parse(result)
34
+ expect(hash).to eq({ "time" => time })
35
+ expect(hash["time"]).to be_a(Time)
36
+ end
37
+ end
38
+
39
+ describe "serializing datetimes" do
40
+ let(:date_time) { random_date_time }
41
+
42
+ subject { PigeonHole.generate(date_time: date_time) }
43
+
44
+ it "serializes hash into a string" do
45
+ result = subject
46
+ expect(result).to_not be_empty
47
+ end
48
+
49
+ it "can be deserialized to a date_time" do
50
+ result = subject
51
+ hash = PigeonHole.parse(result)
52
+ expect(hash["date_time"]).to be_a(DateTime)
53
+ expect(hash["date_time"].to_date).to eq(date_time.to_date)
54
+ expect(hash["date_time"].to_time.to_i).to eq(date_time.to_time.to_i)
55
+ end
56
+ end
57
+
58
+ describe "serializing symbols" do
59
+ let(:symbol) { :a_symbol }
60
+
61
+ subject { PigeonHole.generate(symbol: symbol) }
62
+
63
+ it "serializes hash into a string" do
64
+ result = subject
65
+ expect(result).to_not be_empty
66
+ end
67
+
68
+ it "can be deserialized to a symbol" do
69
+ result = subject
70
+ hash = PigeonHole.parse(result)
71
+ expect(hash).to eq({ "symbol" => symbol })
72
+ expect(hash["symbol"]).to be_a(Symbol)
73
+ end
74
+ end
75
+
76
+ describe "serializing arrays" do
77
+ let(:array) { [:a_symbol, { "test" => :foo } ] }
78
+
79
+ subject { PigeonHole.generate(array: array) }
80
+
81
+ it "serializes hash into a string" do
82
+ result = subject
83
+ expect(result).to_not be_empty
84
+ end
85
+
86
+ it "can be deserialized to a array" do
87
+ result = subject
88
+ hash = PigeonHole.parse(result)
89
+ expect(hash).to eq({ "array" => array })
90
+ expect(hash["array"]).to be_a(Array)
91
+ end
92
+ end
93
+
94
+ describe "serializing nested hashes" do
95
+ let(:expected) do
96
+ {
97
+ foo: {
98
+ bar: random_time,
99
+ baz: :temp
100
+ }
101
+ }
102
+ end
103
+
104
+ subject { PigeonHole.generate(expected) }
105
+
106
+ it "serializes hash into a string" do
107
+ result = subject
108
+ expect(result).to_not be_empty
109
+ end
110
+
111
+ it "can be deserialized to a symbol" do
112
+ result = subject
113
+ hash = PigeonHole.parse(result)
114
+
115
+ expect(symbolize_hash(hash)).to eq(expected)
116
+ end
117
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe "serializing dates" do
4
+ let(:date) { random_date }
5
+
6
+ subject { PigeonHole.generate(date: date) }
7
+
8
+ it "serializes hash into a string" do
9
+ result = subject
10
+ expect(result).to_not be_empty
11
+ end
12
+
13
+ it "can be deserialized to a date time" do
14
+ result = subject
15
+ hash = PigeonHole.parse(result)
16
+ expect(hash).to eq({ "date" => date })
17
+ expect(hash["date"]).to be_a(Date)
18
+ end
19
+ end
20
+
21
+ describe "serializing times" do
22
+ let(:time) { random_time. }
23
+
24
+ subject { PigeonHole.generate(time: time) }
25
+
26
+ it "serializes hash into a string" do
27
+ result = subject
28
+ expect(result).to_not be_empty
29
+ end
30
+
31
+ it "can be deserialized to a time" do
32
+ result = subject
33
+ hash = PigeonHole.parse(result)
34
+ expect(hash).to eq({ "time" => time })
35
+ expect(hash["time"]).to be_a(Time)
36
+ end
37
+ end
38
+
39
+ describe "serializing datetimes" do
40
+ let(:date_time) { random_date_time }
41
+
42
+ subject { PigeonHole.generate(date_time: date_time) }
43
+
44
+ it "serializes hash into a string" do
45
+ result = subject
46
+ expect(result).to_not be_empty
47
+ end
48
+
49
+ it "can be deserialized to a date_time" do
50
+ result = subject
51
+ hash = PigeonHole.parse(result)
52
+ expect(hash["date_time"]).to be_a(DateTime)
53
+ expect(hash["date_time"].to_date).to eq(date_time.to_date)
54
+ expect(hash["date_time"].to_time.to_i).to eq(date_time.to_time.to_i)
55
+ end
56
+ end
57
+
58
+ describe "serializing symbols" do
59
+ let(:symbol) { :a_symbol }
60
+
61
+ subject { PigeonHole.generate(symbol: symbol) }
62
+
63
+ it "serializes hash into a string" do
64
+ result = subject
65
+ expect(result).to_not be_empty
66
+ end
67
+
68
+ it "can be deserialized to a symbol" do
69
+ result = subject
70
+ hash = PigeonHole.parse(result)
71
+ expect(hash).to eq({ "symbol" => symbol })
72
+ expect(hash["symbol"]).to be_a(Symbol)
73
+ end
74
+ end
75
+
76
+ describe "serializing arrays" do
77
+ let(:array) { [:a_symbol, { "test" => :foo } ] }
78
+
79
+ subject { PigeonHole.generate(array: array) }
80
+
81
+ it "serializes hash into a string" do
82
+ result = subject
83
+ expect(result).to_not be_empty
84
+ end
85
+
86
+ it "can be deserialized to a array" do
87
+ result = subject
88
+ hash = PigeonHole.parse(result)
89
+ expect(hash).to eq({ "array" => array })
90
+ expect(hash["array"]).to be_a(Array)
91
+ end
92
+ end
93
+
94
+ describe "serializing nested hashes" do
95
+ let(:expected) do
96
+ {
97
+ foo: {
98
+ bar: random_time,
99
+ baz: :temp
100
+ }
101
+ }
102
+ end
103
+
104
+ subject { PigeonHole.generate(expected) }
105
+
106
+ it "serializes hash into a string" do
107
+ result = subject
108
+ expect(result).to_not be_empty
109
+ end
110
+
111
+ it "can be deserialized to a symbol" do
112
+ result = subject
113
+ hash = PigeonHole.parse(result)
114
+
115
+ expect(symbolize_hash(hash)).to eq(expected)
116
+ end
117
+ end
@@ -0,0 +1,33 @@
1
+ require 'rake'
2
+ require 'rspec'
3
+
4
+ require "#{Rake.application.original_dir}/lib/pigeon_hole"
5
+
6
+ include PigeonHole
7
+
8
+ def random_integer
9
+ rand(9999)
10
+ end
11
+
12
+ def random_time
13
+ (Time.now - random_integer).to
14
+ end
15
+
16
+ def random_date
17
+ Date.today - random_integer
18
+ end
19
+
20
+ def random_date_time
21
+ DateTime.now
22
+ end
23
+
24
+ def symbolize_hash(obj)
25
+ if obj.is_a?(Hash)
26
+ obj.inject({}) do |memo, (k,v)|
27
+ memo[k.to_sym] = symbolize_hash(v)
28
+ memo
29
+ end
30
+ else
31
+ obj
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require 'rake'
2
+ require 'rspec'
3
+
4
+ require "#{Rake.application.original_dir}/lib/pigeon_hole"
5
+
6
+ include PigeonHole
7
+
8
+ def random_integer
9
+ rand(9999)
10
+ end
11
+
12
+ def random_time
13
+ Time.(Time.now - random_integer).to_i
14
+ end
15
+
16
+ def random_date
17
+ Date.today - random_integer
18
+ end
19
+
20
+ def random_date_time
21
+ DateTime.now
22
+ end
23
+
24
+ def symbolize_hash(obj)
25
+ if obj.is_a?(Hash)
26
+ obj.inject({}) do |memo, (k,v)|
27
+ memo[k.to_sym] = symbolize_hash(v)
28
+ memo
29
+ end
30
+ else
31
+ obj
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require 'rake'
2
+ require 'rspec'
3
+
4
+ require "#{Rake.application.original_dir}/lib/pigeon_hole"
5
+
6
+ include PigeonHole
7
+
8
+ def random_integer
9
+ rand(9999)
10
+ end
11
+
12
+ def random_time
13
+ Time.at(Time.now - random_integer).to_i
14
+ end
15
+
16
+ def random_date
17
+ Date.today - random_integer
18
+ end
19
+
20
+ def random_date_time
21
+ DateTime.now
22
+ end
23
+
24
+ def symbolize_hash(obj)
25
+ if obj.is_a?(Hash)
26
+ obj.inject({}) do |memo, (k,v)|
27
+ memo[k.to_sym] = symbolize_hash(v)
28
+ memo
29
+ end
30
+ else
31
+ obj
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require 'rake'
2
+ require 'rspec'
3
+
4
+ require "#{Rake.application.original_dir}/lib/pigeon_hole"
5
+
6
+ include PigeonHole
7
+
8
+ def random_integer
9
+ rand(9999)
10
+ end
11
+
12
+ def random_time
13
+ Time.at(Time.now - random_integer).to_i
14
+ end
15
+
16
+ def random_date
17
+ Date.today - random_integer
18
+ end
19
+
20
+ def random_date_time
21
+ DateTime.now
22
+ end
23
+
24
+ def symbolize_hash(obj)
25
+ if obj.is_a?(Hash)
26
+ obj.inject({}) do |memo, (k,v)|
27
+ memo[k.to_sym] = symbolize_hash(v)
28
+ memo
29
+ end
30
+ else
31
+ obj
32
+ end
33
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,7 +10,7 @@ def random_integer
10
10
  end
11
11
 
12
12
  def random_time
13
- Time.now - random_integer
13
+ Time.at((Time.now - random_integer).to_i)
14
14
  end
15
15
 
16
16
  def random_date
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pigeon_hole
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
  - Stephen Binns
@@ -74,6 +74,14 @@ files:
74
74
  - spec/integration_spec.rb
75
75
  - spec/monster-vim-2016-07-26-10-29-02.rb
76
76
  - spec/monster-vim-2016-07-26-10-29-53.rb
77
+ - spec/monster-vim-2016-07-26-12-05-32.rb
78
+ - spec/monster-vim-2016-07-26-12-05-33.rb
79
+ - spec/monster-vim-2016-07-26-12-05-34.rb
80
+ - spec/monster-vim-2016-07-26-12-05-35.rb
81
+ - spec/monster-vim-2016-07-26-12-06-22.rb
82
+ - spec/monster-vim-2016-07-26-12-06-32.rb
83
+ - spec/monster-vim-2016-07-26-12-06-33.rb
84
+ - spec/monster-vim-2016-07-26-12-06-34.rb
77
85
  - spec/spec_helper.rb
78
86
  homepage: http://www.cronofy.com
79
87
  licenses:
@@ -103,5 +111,13 @@ test_files:
103
111
  - spec/integration_spec.rb
104
112
  - spec/monster-vim-2016-07-26-10-29-02.rb
105
113
  - spec/monster-vim-2016-07-26-10-29-53.rb
114
+ - spec/monster-vim-2016-07-26-12-05-32.rb
115
+ - spec/monster-vim-2016-07-26-12-05-33.rb
116
+ - spec/monster-vim-2016-07-26-12-05-34.rb
117
+ - spec/monster-vim-2016-07-26-12-05-35.rb
118
+ - spec/monster-vim-2016-07-26-12-06-22.rb
119
+ - spec/monster-vim-2016-07-26-12-06-32.rb
120
+ - spec/monster-vim-2016-07-26-12-06-33.rb
121
+ - spec/monster-vim-2016-07-26-12-06-34.rb
106
122
  - spec/spec_helper.rb
107
123
  has_rdoc: