field_mapper 0.2.0 → 0.2.1

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: bfe9de882a181be20182dea8a1808194d5cee08e
4
- data.tar.gz: b269ff64187a983f56600042a8bd88e06109cfe2
3
+ metadata.gz: 6c52bf2ca07222946b8825250bb569f9997497fb
4
+ data.tar.gz: 6c0855100f5359f5458fca4a78919c77fd5166e0
5
5
  SHA512:
6
- metadata.gz: 3929ca29c513a13421ca4e7718388b84e5f5010e9b6a4ea8acbebe06bc96b39fbcb8be7613372ca9aefb35bd47ba067d03f19061978b6dedc04f54b6f19ad13b
7
- data.tar.gz: 79e599d3b463d31d19c33f9e968e9f35fa9f28fea8239903798e7381895547a988effad49d48f4bc10d14ff925e2013e6a088200d9d93619f90bcaa3645f6003
6
+ metadata.gz: 7fa9c0f0a58f0a85a9c743924a9cb42d0ed60adc761c28d85484260a3571d9d7620af84ecbbc3ac46503e2586db9b4c94d947f210e9371a84865b9daf187ee47
7
+ data.tar.gz: cc849900d7fd3a10f3b1fdcd0efe8408b2d1d70d784a07ea3b3b3f603f868fdd9f8a3384f3670d2f7692c9221886130daab91d9fa6b84ca72aa5061df0c14bc1
@@ -109,21 +109,16 @@ module FieldMapper
109
109
  def cast_value(type, value, as_single_value: false)
110
110
  return nil if value.nil?
111
111
  case type.name
112
- when "String" then return value.to_s.strip
113
- when "FieldMapper::Types::Boolean" then return FieldMapper::Types::Boolean.parse(value)
114
- when "Time" then
115
- return value if value.is_a?(Time)
116
- return Time.parse(value.to_s) rescue nil
112
+ when "String" then return string(value)
113
+ when "FieldMapper::Types::Boolean" then return boolean(value)
114
+ when "Time" then return time(value)
117
115
  when "Integer" then return value.to_i
118
116
  when "Float" then return value.to_f
119
- when "Money" then
120
- return value if value.is_a?(Money)
121
- return Monetize.parse(value) rescue nil
117
+ when "Money" then return money(value)
122
118
  when "FieldMapper::Types::Plat" then return plat_instance(type, value)
123
119
  when "FieldMapper::Types::List" then
124
- return value if value.is_a?(Array) && value.empty?
125
- return plat_instance_list(type, value) if type.plat_list?
126
120
  return cast_value(type.type, value) if as_single_value
121
+ return plat_instance_list(type, value) if type.plat_list?
127
122
  get_list value
128
123
  else
129
124
  nil
@@ -141,6 +136,26 @@ module FieldMapper
141
136
  value & raw_values
142
137
  end
143
138
 
139
+ def string(value)
140
+ return value if value.is_a?(String)
141
+ value.to_s.strip
142
+ end
143
+
144
+ def boolean(value)
145
+ return value if value.is_a?(TrueClass) || value.is_a?(FalseClass)
146
+ FieldMapper::Types::Boolean.parse(value)
147
+ end
148
+
149
+ def time(value)
150
+ return value if value.is_a?(Time)
151
+ Time.parse(value.to_s) rescue nil
152
+ end
153
+
154
+ def money(value)
155
+ return value if value.is_a?(Money)
156
+ return Monetize.parse(value) rescue nil
157
+ end
158
+
144
159
  def plat_instance(type, value)
145
160
  return value if value.is_a?(FieldMapper::Standard::Plat)
146
161
  return value if value.is_a?(Numeric)
@@ -151,7 +166,7 @@ module FieldMapper
151
166
  end
152
167
 
153
168
  def plat_instance_list(type, value)
154
- return value if value.empty?
169
+ return value if value.is_a?(Array) && value.empty?
155
170
  value = unmarshal(value) if value.is_a?(String)
156
171
  return value.map { |val| plat_instance(type, val) }
157
172
  end
@@ -1,3 +1,3 @@
1
1
  module FieldMapper
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: field_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins