Class: Conformity::Field
- Inherits:
-
Object
- Object
- Conformity::Field
- Defined in:
- lib/conformity/field.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ Field
constructor
A new instance of Field.
- #required? ⇒ Boolean
- #value ⇒ Object
- #value=(value) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Field
Returns a new instance of Field.
6 7 8 9 10 |
# File 'lib/conformity/field.rb', line 6 def initialize(name, = {}) @name = name @options = [:options] @required = [:required] || false end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/conformity/field.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/conformity/field.rb', line 3 def @options end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/conformity/field.rb', line 4 def type @type end |
Instance Method Details
#required? ⇒ Boolean
12 13 14 |
# File 'lib/conformity/field.rb', line 12 def required? @required end |
#value ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/conformity/field.rb', line 16 def value if @value @value elsif required? raise FieldError, "Required field '#{name}' not set" end end |
#value=(value) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/conformity/field.rb', line 24 def value=(value) if @options && !@options.include?(value) raise FieldError, "#{value} not in #{@options}" end @value = value end |