Class: Spectifly::Base::Field

Inherits:
EntityNode show all
Defined in:
lib/spectifly/base/field.rb

Direct Known Subclasses

Json::Field, Xsd::Field

Instance Attribute Summary

Attributes inherited from EntityNode

#attributes, #description, #example, #inherits_from, #name, #restrictions, #validations

Instance Method Summary collapse

Methods inherited from EntityNode

#display_type, #initialize, #required?, #unique?

Constructor Details

This class inherits a constructor from Spectifly::Base::EntityNode

Instance Method Details

#extract_attributesObject



6
7
8
9
10
11
12
# File 'lib/spectifly/base/field.rb', line 6

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

#extract_restrictionsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/spectifly/base/field.rb', line 14

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

#multiple?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/spectifly/base/field.rb', line 37

def multiple?
  @multiple
end

#typeObject



31
32
33
34
35
# File 'lib/spectifly/base/field.rb', line 31

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