Module: CustomFielder::DeserializationHelper
Constant Summary collapse
- FALSE_VALUES =
[false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF']
Instance Method Summary collapse
- #array(value) ⇒ Array
- #boolean(value) ⇒ Boolean
- #date(value) ⇒ Date
- #date_time(value) ⇒ DateTime
-
#deserialize(type, value) ⇒ Array|Integer|Float|Date|DateTime|Boolean|String
Runs the the deserialization function for the passed type.
- #fixnum(value) ⇒ Integer
- #float(value) ⇒ Float
- #string(value) ⇒ String
Instance Method Details
#array(value) ⇒ Array
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/custom_fielder/deserialization_helper.rb', line 21 def array(value) value.delete('[]"').split(', ').map do |val| case val when /^\d+$/ val.to_i when /^\d+\.\d+$/ val.to_f when /^\d{4}-\d{2}-\d{2}$/ date(val) when /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}-\d{2}:\d{2}$/ date_time(val) when 'true' true when 'false' false when /".+"/ val.delete('"') else val end end end |
#boolean(value) ⇒ Boolean
75 76 77 |
# File 'app/helpers/custom_fielder/deserialization_helper.rb', line 75 def boolean(value) FALSE_VALUES.include?(value) ? false : true end |
#date(value) ⇒ Date
61 62 63 |
# File 'app/helpers/custom_fielder/deserialization_helper.rb', line 61 def date(value) Date.parse(value) end |
#date_time(value) ⇒ DateTime
68 69 70 |
# File 'app/helpers/custom_fielder/deserialization_helper.rb', line 68 def date_time(value) DateTime.parse(value) end |
#deserialize(type, value) ⇒ Array|Integer|Float|Date|DateTime|Boolean|String
Runs the the deserialization function for the passed type
14 15 16 |
# File 'app/helpers/custom_fielder/deserialization_helper.rb', line 14 def deserialize(type, value) send("#{type.underscore}", value) end |
#fixnum(value) ⇒ Integer
47 48 49 |
# File 'app/helpers/custom_fielder/deserialization_helper.rb', line 47 def fixnum(value) value.to_i end |
#float(value) ⇒ Float
54 55 56 |
# File 'app/helpers/custom_fielder/deserialization_helper.rb', line 54 def float(value) value.to_f end |
#string(value) ⇒ String
82 83 84 |
# File 'app/helpers/custom_fielder/deserialization_helper.rb', line 82 def string(value) value end |