Module: ConvertValue
- Defined in:
- lib/helpers/convert_value.rb
Class Method Summary collapse
-
.convert_to_string(value, type) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength.
-
.convert_to_type(value, type) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength.
Class Method Details
.convert_to_string(value, type) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/helpers/convert_value.rb', line 26 def convert_to_string(value, type) case type when 'Hash', 'Hashie::Mash' value.to_json when 'Array' value.join('|||') else value.to_s end end |
.convert_to_type(value, type) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/helpers/convert_value.rb', line 4 def convert_to_type(value, type) case type when 'String' value.to_s when 'TrueClass' true when 'NilClass', 'FalseClass' false when 'Fixnum', 'Integer' value.to_i when 'Float' value.to_f when 'Symbol' value.to_sym when 'Array' value.split('|||') when 'Hash' Hashie::Mash.new(JSON.parse(value)) end end |