convertable_values 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/convertable_values.gemspec +3 -3
- data/lib/convertable_values.rb +7 -7
- metadata +44 -22
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/convertable_values.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{convertable_values}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Stephen Blankenship"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-05-03}
|
13
13
|
s.description = %q{Convertable Values provides a simple unit conversion library and pattern for transparently storing base units.
|
14
14
|
Example usage: You have a model that wants to store values with units (e.g., 200 lbs), but you want (or at least should want)
|
15
15
|
to store all the values in a base unit (e.g., 90.718474 kilograms). This gem makes using this design pattern totally transparent.}
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
s.homepage = %q{http://github.com/stephenb/convertable_values}
|
36
36
|
s.licenses = ["MIT"]
|
37
37
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.
|
38
|
+
s.rubygems_version = %q{1.7.2}
|
39
39
|
s.summary = %q{Convertable Values provides a simple unit conversion library and pattern for transparently storing base units.}
|
40
40
|
s.test_files = [
|
41
41
|
"test/helper.rb",
|
data/lib/convertable_values.rb
CHANGED
@@ -18,13 +18,13 @@ module ConvertableValues
|
|
18
18
|
|
19
19
|
if new_value && unit_str
|
20
20
|
# store the value converted to the base unit corresponding to the given unit
|
21
|
-
if respond_to?(:write_attribute)
|
21
|
+
if respond_to?(:write_attribute, true)
|
22
22
|
write_attribute(value_attr.to_sym, new_value.send(unit_str))
|
23
23
|
else
|
24
24
|
instance_variable_set("@#{value_attr}".to_sym, new_value.send(unit_str))
|
25
25
|
end
|
26
26
|
else
|
27
|
-
if respond_to?(:write_attribute)
|
27
|
+
if respond_to?(:write_attribute, true)
|
28
28
|
write_attribute(value_attr.to_sym, new_value)
|
29
29
|
else
|
30
30
|
instance_variable_set("@#{value_attr}".to_sym, new_value)
|
@@ -38,13 +38,13 @@ module ConvertableValues
|
|
38
38
|
|
39
39
|
if unit_str
|
40
40
|
# return the value converted back to whatever unit was stored
|
41
|
-
if respond_to?(:read_attribute)
|
41
|
+
if respond_to?(:read_attribute, true)
|
42
42
|
read_attribute(value_attr.to_sym).to(unit_str.to_sym)
|
43
43
|
else
|
44
44
|
instance_variable_get("@#{value_attr}".to_sym).to(unit_str.to_sym)
|
45
45
|
end
|
46
46
|
else
|
47
|
-
if respond_to?(:read_attribute)
|
47
|
+
if respond_to?(:read_attribute, true)
|
48
48
|
read_attribute(value_attr.to_sym)
|
49
49
|
else
|
50
50
|
instance_variable_get("@#{value_attr}".to_sym)
|
@@ -54,20 +54,20 @@ module ConvertableValues
|
|
54
54
|
|
55
55
|
# Create override method for updating value when unit is set/changed
|
56
56
|
define_method "#{unit_attr}=".to_sym do |new_unit|
|
57
|
-
if respond_to?(:read_attribute)
|
57
|
+
if respond_to?(:read_attribute, true)
|
58
58
|
old_unit = read_attribute(unit_attr.to_sym)
|
59
59
|
else
|
60
60
|
old_unit = instance_variable_get("@#{unit_attr}".to_sym)
|
61
61
|
end
|
62
62
|
|
63
|
-
if respond_to?(:write_attribute)
|
63
|
+
if respond_to?(:write_attribute, true)
|
64
64
|
write_attribute(unit_attr.to_sym, new_unit)
|
65
65
|
else
|
66
66
|
instance_variable_set("@#{unit_attr}".to_sym, new_unit)
|
67
67
|
end
|
68
68
|
|
69
69
|
# Re-assign the value so it will be converted properly
|
70
|
-
if respond_to?(:read_attribute)
|
70
|
+
if respond_to?(:read_attribute, true)
|
71
71
|
value = read_attribute(value_attr.to_sym)
|
72
72
|
else
|
73
73
|
value = instance_variable_get("@#{value_attr}".to_sym)
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: convertable_values
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Stephen Blankenship
|
@@ -10,53 +15,68 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
18
|
+
date: 2011-05-03 00:00:00 Z
|
15
19
|
dependencies:
|
16
20
|
- !ruby/object:Gem::Dependency
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
19
22
|
none: false
|
20
23
|
requirements:
|
21
24
|
- - ">="
|
22
25
|
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
23
29
|
version: "0"
|
24
|
-
|
30
|
+
name: shoulda
|
25
31
|
prerelease: false
|
26
|
-
|
32
|
+
type: :development
|
33
|
+
requirement: *id001
|
27
34
|
- !ruby/object:Gem::Dependency
|
28
|
-
|
29
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
35
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
30
36
|
none: false
|
31
37
|
requirements:
|
32
38
|
- - ~>
|
33
39
|
- !ruby/object:Gem::Version
|
40
|
+
hash: 23
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 0
|
44
|
+
- 0
|
34
45
|
version: 1.0.0
|
35
|
-
|
46
|
+
name: bundler
|
36
47
|
prerelease: false
|
37
|
-
|
48
|
+
type: :development
|
49
|
+
requirement: *id002
|
38
50
|
- !ruby/object:Gem::Dependency
|
39
|
-
|
40
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
41
52
|
none: false
|
42
53
|
requirements:
|
43
54
|
- - ~>
|
44
55
|
- !ruby/object:Gem::Version
|
56
|
+
hash: 1
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 5
|
60
|
+
- 1
|
45
61
|
version: 1.5.1
|
46
|
-
|
62
|
+
name: jeweler
|
47
63
|
prerelease: false
|
48
|
-
|
64
|
+
type: :development
|
65
|
+
requirement: *id003
|
49
66
|
- !ruby/object:Gem::Dependency
|
50
|
-
|
51
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
52
68
|
none: false
|
53
69
|
requirements:
|
54
70
|
- - ">="
|
55
71
|
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
56
75
|
version: "0"
|
57
|
-
|
76
|
+
name: rcov
|
58
77
|
prerelease: false
|
59
|
-
|
78
|
+
type: :development
|
79
|
+
requirement: *id004
|
60
80
|
description: |-
|
61
81
|
Convertable Values provides a simple unit conversion library and pattern for transparently storing base units.
|
62
82
|
Example usage: You have a model that wants to store values with units (e.g., 200 lbs), but you want (or at least should want)
|
@@ -82,7 +102,6 @@ files:
|
|
82
102
|
- lib/numeric/numeric_units.rb
|
83
103
|
- test/helper.rb
|
84
104
|
- test/test_convertable_values.rb
|
85
|
-
has_rdoc: true
|
86
105
|
homepage: http://github.com/stephenb/convertable_values
|
87
106
|
licenses:
|
88
107
|
- MIT
|
@@ -96,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
115
|
requirements:
|
97
116
|
- - ">="
|
98
117
|
- !ruby/object:Gem::Version
|
99
|
-
hash:
|
118
|
+
hash: 3
|
100
119
|
segments:
|
101
120
|
- 0
|
102
121
|
version: "0"
|
@@ -105,11 +124,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
124
|
requirements:
|
106
125
|
- - ">="
|
107
126
|
- !ruby/object:Gem::Version
|
127
|
+
hash: 3
|
128
|
+
segments:
|
129
|
+
- 0
|
108
130
|
version: "0"
|
109
131
|
requirements: []
|
110
132
|
|
111
133
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.
|
134
|
+
rubygems_version: 1.7.2
|
113
135
|
signing_key:
|
114
136
|
specification_version: 3
|
115
137
|
summary: Convertable Values provides a simple unit conversion library and pattern for transparently storing base units.
|