Class: LessonlyApi::Utils::CustomFieldConverter
- Inherits:
-
Object
- Object
- LessonlyApi::Utils::CustomFieldConverter
- Defined in:
- lib/lessonly_api/utils/custom_field_converter.rb
Constant Summary collapse
- CONVERSIONS =
{ big_decimal: ->(val) { val.is_a?(BigDecimal) ? val : val && BigDecimal(val.to_s) }, date: ->(val) { val.is_a?(Date) ? val : val && Date.parse(val) }, date_time: ->(val) { val.is_a?(DateTime) ? val : val && DateTime.parse(val) } }.freeze
Instance Method Summary collapse
- #convert(value) ⇒ Object
-
#initialize(data_type) ⇒ CustomFieldConverter
constructor
A new instance of CustomFieldConverter.
Constructor Details
#initialize(data_type) ⇒ CustomFieldConverter
Returns a new instance of CustomFieldConverter.
14 15 16 |
# File 'lib/lessonly_api/utils/custom_field_converter.rb', line 14 def initialize(data_type) @data_type = data_type end |
Instance Method Details
#convert(value) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/lessonly_api/utils/custom_field_converter.rb', line 18 def convert(value) if @data_type.is_a?(Array) convert_array(value) elsif CONVERSIONS.key?(@data_type) CONVERSIONS[@data_type].call(value) else wrap(value, @data_type) end end |