Sha256: 148a42205a53ed437c191465e33a45f49620787335afb4de0c83ba499d3090cd

Contents?: true

Size: 1.07 KB

Versions: 11

Compression:

Stored size: 1.07 KB

Contents

require_relative 'entity_node'

module Spectifly
  module Base
    class Field < EntityNode
      def extract_attributes
        super
        @multiple = @attributes.delete('Multiple') == true
        if @tokens.include?('?') && @type && @type != 'Boolean'
          raise ArgumentError, "Boolean field has conflicting type"
        end
      end

      def extract_restrictions
        super
        ['Minimum Value', 'Maximum Value', 'Valid Values'].each do |restriction|
          if @attributes[restriction]
            token = Spectifly::Support.tokenize(restriction)
            @restrictions[token] = @attributes.delete(restriction)
          end
        end
        @validations.each do |validation|
          if validation =~ /^Must match regex "(.*)"$/
            @validations.delete(validation)
            @restrictions['regex'] = /#{$1}/
          end
        end
        @restrictions
      end

      def type
        type = super
        type = 'boolean' if @tokens.include?('?')
        type || 'string'
      end

      def multiple?
        @multiple
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spectifly-0.0.11 lib/spectifly/base/field.rb
spectifly-0.0.10 lib/spectifly/base/field.rb
spectifly-0.0.9 lib/spectifly/base/field.rb
spectifly-0.0.8 lib/spectifly/base/field.rb
spectifly-0.0.7 lib/spectifly/base/field.rb
spectifly-0.0.6 lib/spectifly/base/field.rb
spectifly-0.0.5 lib/spectifly/base/field.rb
spectifly-0.0.4 lib/spectifly/base/field.rb
spectifly-0.0.3 lib/spectifly/base/field.rb
spectifly-0.0.2 lib/spectifly/base/field.rb
spectifly-0.0.1 lib/spectifly/base/field.rb