module Ecoportal module API class V1 class SchemaField < Common::BaseModel passthrough :id, :alt_id, :name, :optional, :shared, :multiple, :type, :options def parse_text(value) values = [*value.to_s.lines].map do |line| line = line.chomp next if line == "" case type when "text", "phone_number" line when "number" Float(line) rescue return nil, false when "boolean" %w[true TRUE True Y y YES X x].include?(line) when "select" return nil, false unless options.include?(line) line when "date" Date.parse(line) rescue return nil, false end end.compact out = values out = values.first unless multiple [out, true] end end end end end