typed 0.2.2 → 0.2.3

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.
data/lib/typed/hash.rb CHANGED
@@ -128,6 +128,10 @@ module Typed
128
128
  self[key].must.coerced(Pathname, String=>proc{|i| Pathname(i)})
129
129
  end
130
130
 
131
+ def time(key)
132
+ self[key].must.coerced(Time, Fixnum=>proc{|i| Time.at(i)})
133
+ end
134
+
131
135
  ######################################################################
132
136
  ### Utils
133
137
 
data/lib/typed/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Typed
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/spec/time_spec.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe Typed::Hash do
4
+ let(:data) { Typed::Hash.new }
5
+
6
+ describe "#time" do
7
+ it "should return a Time when it is a Fixnum" do
8
+ data["now"] = Time.mktime(2012,5,15).to_i
9
+ data.time("now").should == Time.mktime(2012,5,15)
10
+ end
11
+
12
+ it "should return itself when it is a Time" do
13
+ data["now"] = Time.mktime(2012,5,15)
14
+ data.time("now").should == Time.mktime(2012,5,15)
15
+ end
16
+
17
+ it "should raise Must::Invalid if not time-able" do
18
+ data["now"] = "x"
19
+
20
+ lambda {
21
+ data.time("now")
22
+ }.should raise_error(Must::Invalid)
23
+ end
24
+ end
25
+ end
26
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typed
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - maiha
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-07 00:00:00 +09:00
18
+ date: 2012-05-31 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -92,6 +92,7 @@ files:
92
92
  - spec/path_spec.rb
93
93
  - spec/schema_spec.rb
94
94
  - spec/spec_helper.rb
95
+ - spec/time_spec.rb
95
96
  - typed.gemspec
96
97
  has_rdoc: true
97
98
  homepage: https://github.com/maiha/typed