setsumei 0.0.8 → 0.0.9
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/setsumei/build.rb +9 -1
- data/lib/setsumei/version.rb +1 -1
- data/spec/setsumei/build_spec.rb +23 -0
- metadata +2 -2
data/lib/setsumei/build.rb
CHANGED
@@ -3,8 +3,10 @@ require 'setsumei/build/key'
|
|
3
3
|
module Setsumei
|
4
4
|
module Build
|
5
5
|
def Build.a(klass,options = {})
|
6
|
-
inform_developer "#{klass} should be able to list its attributes" unless klass.respond_to? :defined_attributes
|
7
6
|
inform_developer "wrong number of arguments, options must include { from: data }" unless options.keys.include? :from
|
7
|
+
detect_string(klass) and return(options[:from].to_s)
|
8
|
+
detect_float(klass) and return(options[:from].to_f)
|
9
|
+
inform_developer "#{klass} should be able to list its attributes" unless klass.respond_to? :defined_attributes
|
8
10
|
|
9
11
|
klass.new.tap do |object|
|
10
12
|
klass.defined_attributes.each do |_,attribute|
|
@@ -17,5 +19,11 @@ module Setsumei
|
|
17
19
|
def self.inform_developer(message)
|
18
20
|
raise ArgumentError.new message
|
19
21
|
end
|
22
|
+
def self.detect_string(klass)
|
23
|
+
klass == String
|
24
|
+
end
|
25
|
+
def self.detect_float(klass)
|
26
|
+
klass == Float
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
data/lib/setsumei/version.rb
CHANGED
data/spec/setsumei/build_spec.rb
CHANGED
@@ -28,7 +28,30 @@ module Setsumei
|
|
28
28
|
end
|
29
29
|
it { should == object }
|
30
30
|
end
|
31
|
+
describe ".a(String,from: hash_data)" do
|
32
|
+
let(:hash_data) { mock "hash_data", to_s: string }
|
33
|
+
let(:string) { mock "string" }
|
31
34
|
|
35
|
+
subject { Build.a String, from: hash_data }
|
36
|
+
|
37
|
+
it "should call to_s on hash_data" do
|
38
|
+
hash_data.should_receive(:to_s).and_return(string)
|
39
|
+
subject
|
40
|
+
end
|
41
|
+
it { should == string }
|
42
|
+
end
|
43
|
+
describe ".a(Float,from: hash_data)" do
|
44
|
+
let(:hash_data) { mock "hash_data", to_f: float }
|
45
|
+
let(:float) { mock "float" }
|
46
|
+
|
47
|
+
subject { Build.a Float, from: hash_data }
|
48
|
+
|
49
|
+
it "should call to_f on hash_data" do
|
50
|
+
hash_data.should_receive(:to_f).and_return(float)
|
51
|
+
subject
|
52
|
+
end
|
53
|
+
it { should == float }
|
54
|
+
end
|
32
55
|
describe ".a(klass,from: hash_data) error conditions" do
|
33
56
|
context "klass doesn't have defined attributes" do
|
34
57
|
let(:klass) { mock "class" }
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: setsumei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.9
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jon Rowe
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-16 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|