168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/sheets_db/worksheet.rb', line 168
def convert_value(raw_value, attribute_definition)
raw_value = raw_value.strip if attribute_definition.fetch(:strip, true)
return nil if raw_value == ""
converted_value = case attribute_definition[:type].to_s
when "Integer"
raw_value.to_i
when "Float"
raw_value.to_f
when "DateTime"
DateTime.strptime(raw_value, "%m/%d/%Y %H:%M:%S")
when "Boolean"
convert_to_boolean(raw_value)
else
raw_value
end
attribute_definition[:transform] ?
attribute_definition[:transform].call(converted_value) :
converted_value
end
|