Sha256: 8546049cef2e53ca2d905d946ccf839a3fe0ea08e0c3f2b552ac2671abe9ef67

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Eddy
  module Element

    # Identifier (works with a code list specified by the dictionary).
    class ID < Element::Base
      # @return [Array<String>]
      def code_list
        raise NotImplementedError, "Each ID element must define its own code_list"
      end

      # @param min [Integer]
      # @param max [Integer]
      # @return [void]
      def initialize(min, max)
        self.min = min
        self.max = max
      end

      # @return [String]
      def value()
        # raise Eddy::ElementNilValueError if @value.nil?
        return @value
      end

      # @param arg [String]
      # return [void]
      def value=(arg)
        if arg.nil?
          @value = arg
          return
        end
        raise Eddy::ElementValidationError, "value not present in code list" unless self.code_list().include?(arg)
        raise Eddy::ElementValidationError, "value can't be shorter than #{self.min}" if arg.length < self.min
        raise Eddy::ElementValidationError, "value can't be longer than #{self.max}" if arg.length > self.max
        @value = arg
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eddy-0.1.0 lib/eddy/element/id.rb