Class: Datev::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/datev/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={}, &block)
  unless name.is_a?(String)
    raise ArgumentError.new("Argument 'name' has to be a String")
  end

  unless options.is_a?(Hash)
    raise ArgumentError.new("Argument 'options' has to be a Hash")
  end

  self.name = name
  self.options = options

  if block_given?
    self.instance_eval(&block)
  end
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/datev/field.rb', line 3

def block
  @block
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/datev/field.rb', line 3

def name
  @name
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/datev/field.rb', line 3

def options
  @options
end

Instance Method Details

#required?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/datev/field.rb', line 22

def required?
  options[: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