Sha256: 462ee46d4b2ab493589fc2ce3edd888aec542d5369d5f48da5ff1d88a93f08ae

Contents?: true

Size: 961 Bytes

Versions: 20

Compression:

Stored size: 961 Bytes

Contents

module Ecoportal
  module API
    class V1
      class SchemaField < Common::BaseModel
        passthrough :id, :alt_id, :name, :optional, :shared, :multiple, :type, :options, to: :doc

        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
          if multiple
            return values, true
          else
            return values.first, true
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ecoportal-api-0.3.8 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.3.6 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.3.5 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.3.4 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.3.3 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.3.1 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.3.0 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.3.0.pre1 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.2.2 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.2.1 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.2.0 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.1.12 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.1.11 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.1.10 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.1.9 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.1.8 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.1.7 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.1.6 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.1.5 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.1.4 lib/ecoportal/api/v1/schema_field.rb