class ParamsProcessor::TypeConvert
Public Class Methods
all_of()
click to toggle source
combined TODO
# File lib/params_processor/type_convert.rb, line 56 def all_of doc = ParamDoc.new name: @doc.name, schema: @doc.all_of.reduce({}, :merge) TypeConvert.(@input, based_on: doc) end
any_of()
click to toggle source
# File lib/params_processor/type_convert.rb, line 66 def any_of doc = ParamDoc.new name: @doc.name, schema: @doc.all_of.reduce({}, :merge) TypeConvert.(@input, based_on: doc) end
array()
click to toggle source
# File lib/params_processor/type_convert.rb, line 44 def array return @input unless @input.is_a?(String) @input = MultiJson.load(@input) end
boolean()
click to toggle source
# File lib/params_processor/type_convert.rb, line 29 def boolean @input.to_s.in?(%w[ true 1 ]) ? true : false end
call(input, based_on:)
click to toggle source
# File lib/params_processor/type_convert.rb, line 6 def call(input, based_on:) @input = input @doc = based_on convert end
convert()
click to toggle source
TODO: 循环和递归转换
# File lib/params_processor/type_convert.rb, line 13 def convert send(@doc.type || @doc.combined_modes.first) # TODO rescue NoMethodError @input end
integer()
click to toggle source
int32 / int64
# File lib/params_processor/type_convert.rb, line 20 def integer @input.to_i end
not()
click to toggle source
# File lib/params_processor/type_convert.rb, line 71 def not @input end
number()
click to toggle source
float / double
# File lib/params_processor/type_convert.rb, line 25 def number @input.to_f end
object()
click to toggle source
# File lib/params_processor/type_convert.rb, line 49 def object return @input unless @input.is_a?(String) @input = MultiJson.load(@input) end
one_of()
click to toggle source
# File lib/params_processor/type_convert.rb, line 61 def one_of doc = ParamDoc.new name: @doc.name, schema: @doc.all_of.reduce({}, :merge) TypeConvert.(@input, based_on: doc) end
parse_time(cls)
click to toggle source
helpers
# File lib/params_processor/type_convert.rb, line 77 def parse_time(cls) if @doc.pattern cls.send(:strptime, @input, @doc.pattern) else cls.send(:parse, @input) end end
string()
click to toggle source
date / date-time / base64
# File lib/params_processor/type_convert.rb, line 34 def string case @doc.format when 'date' then parse_time(Date) when 'date-time' then parse_time(DateTime) when 'base64' then @input # Base64.strict_decode64(@input) when 'binary' then @input else @input.to_s end end