Sha256: fd3a3098ef8f5037cf652d2a6e2160e97b67873fab9ebcbb8145947600b15e14

Contents?: true

Size: 691 Bytes

Versions: 12

Compression:

Stored size: 691 Bytes

Contents

module Datev
  class Field
    attr_accessor :name, :options, :block

    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

    def required?
      options[:required] == true
    end

    def validate!(value)
      if value.nil?
        raise ArgumentError.new("Value for field '#{name}' is required") if required?
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
datev-0.11.0 lib/datev/field.rb
datev-0.10.0 lib/datev/field.rb
datev-0.9.0 lib/datev/field.rb
datev-0.8.2 lib/datev/field.rb
datev-0.8.1 lib/datev/field.rb
datev-0.8.0 lib/datev/field.rb
datev-0.7.0 lib/datev/field.rb
datev-0.6.0 lib/datev/field.rb
datev-0.5.1 lib/datev/field.rb
datev-0.5.0 lib/datev/field.rb
datev-0.4.0 lib/datev/field.rb
datev-0.3.1 lib/datev/field.rb