Class: Datev::Field
- Inherits:
-
Object
- Object
- Datev::Field
- Defined in:
- lib/datev/field.rb
Direct Known Subclasses
BooleanField, DateField, DecimalField, IntegerField, StringField
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(name, options = {}, &block) ⇒ Field
constructor
A new instance of Field.
- #required? ⇒ Boolean
- #validate!(value) ⇒ Object
Constructor Details
#initialize(name, options = {}, &block) ⇒ Field
Returns a new instance of Field.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/datev/field.rb', line 5 def initialize(name, ={}, &block) unless name.is_a?(String) raise ArgumentError.new("Argument 'name' has to be a String") end unless .is_a?(Hash) raise ArgumentError.new("Argument 'options' has to be a Hash") end self.name = name self. = if block_given? self.instance_eval(&block) end end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
3 4 5 |
# File 'lib/datev/field.rb', line 3 def block @block end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/datev/field.rb', line 3 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/datev/field.rb', line 3 def @options end |
Instance Method Details
#required? ⇒ Boolean
22 23 24 |
# File 'lib/datev/field.rb', line 22 def required? [:required] == true end |
#validate!(value) ⇒ Object
26 27 28 29 30 |
# File 'lib/datev/field.rb', line 26 def validate!(value) if value.nil? raise ArgumentError.new("Value for field '#{name}' is required") if required? end end |