Sha256: 726c0d9d391294bb9311fddf5652ba14809c1f1ed5eddcbd706acdd44ea548da

Contents?: true

Size: 951 Bytes

Versions: 21

Compression:

Stored size: 951 Bytes

Contents

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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ecoportal-api-0.8.5 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.8.4 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.8.3 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.8.2 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.7.5 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.7.4 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.7.3 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.7.2 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.7.1 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.7.0 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.6.0 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.5.8 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.5.7 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.5.6 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.5.5 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.5.3 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.5.1 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.5.0 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.4.3 lib/ecoportal/api/v1/schema_field.rb
ecoportal-api-0.4.2 lib/ecoportal/api/v1/schema_field.rb