Sha256: a94b1242d5302682b13817bdf4f1500e1a4fc1dea1067801ae74fb0d0c9cac07

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Eddy
  module Element
    # Numeric (implies the number of decimal points, e.g., N2 would be two decimal positions)
    class N < Base
      # Number of decimal points.
      # @return [Integer]
      attr_accessor :decimal_points

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

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

      # @param arg [Integer]
      # @raise [Eddy::ElementValidationError]
      # @return [void]
      def value=(arg)
        if arg.nil?
          @value = arg
          return
        end
        raise Eddy::ElementValidationError, "value needs to be an integer" unless arg.is_a?(Integer)
        raise Eddy::ElementValidationError, "value can't be shorter than #{self.min}" if arg.to_s.length < self.min
        raise Eddy::ElementValidationError, "value can't be longer than #{self.max}" if arg.to_s.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/n.rb