Class: Spectifly::Json::Field
- Inherits:
-
Base::Field
- Object
- Base::EntityNode
- Base::Field
- Spectifly::Json::Field
- Defined in:
- lib/spectifly/json/field.rb
Instance Attribute Summary
Attributes inherited from Base::EntityNode
#attributes, #description, #example, #inherits_from, #name, #validations
Instance Method Summary collapse
Methods inherited from Base::Field
#extract_attributes, #extract_restrictions, #multiple?, #type
Methods inherited from Base::EntityNode
#display_type, #extract_attributes, #extract_restrictions, #initialize, #required?, #type, #unique?
Constructor Details
This class inherits a constructor from Spectifly::Base::EntityNode
Instance Method Details
#restrictions ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/spectifly/json/field.rb', line 19 def restrictions @restrictions.inject({}) do |result, (type, value)| value = value.source if type == 'regex' result[type] = value result end end |
#to_h ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/spectifly/json/field.rb', line 4 def to_h fields = { :type => type, :multiple => multiple?, :required => required?, } [:description, :example, :validations, :restrictions].each do |opt| value = self.send(opt) if value && !value.empty? fields[opt] = value end end { name.to_sym => fields} end |