class Eddy::Models::Element::R

Decimal Numeric (decimal points must be transmitted if used).

Public Class Methods

new( min:, max:, req: nil, ref: nil, val: nil ) click to toggle source

@param min [Integer] @param max [Integer] @param req [String] (nil) @param ref [String] (nil) @param val [Numeric] (nil) @return [void]

# File lib/eddy/models/element/r.rb, line 15
def initialize(
  min:,
  max:,
  req: nil,
  ref: nil,
  val: nil
)
  @type = "R"
  @min = min
  @max = max
  self.req = req
  self.ref = ref
  self.value = val
end
process_value(val, max) click to toggle source

Stringify a numeric value and trim it to `max`.

TODO: Use `sprintf` here?

See:

@param val [Numeric] @param max [Integer] @return [String]

# File lib/eddy/models/element/r.rb, line 68
def self.process_value(val, max)
  case val
  when Integer
    return val.to_s.slice(0..max)
  when Float
    # FIXME: This isn't correct.
    return val.to_s.slice(0..(max + 1))
  when Complex
    # TODO: Handle case
    raise NotImplementedError, "eddy: support for Complex types in R data elements has not been implemented."
  when Rational
    # TODO: Handle case
    raise NotImplementedError, "eddy: support for Rational types in R data elements has not been implemented."
  when BigDecimal
    # TODO: Handle case
    raise NotImplementedError, "eddy: support for BigDecimal types in R data elements has not been implemented."
    # return val.to_f.to_s.slice(0..(max + 1))
  end
end

Public Instance Methods

process_value() click to toggle source

@return [String]

# File lib/eddy/models/element/r.rb, line 52
def process_value()
  return self.class.process_value(@val, self.max)
end
value() click to toggle source

@return [String]

Calls superclass method Eddy::Models::Element::Base#value
# File lib/eddy/models/element/r.rb, line 47
def value()
  return super()
end
value=(arg) click to toggle source

@param arg [Numeric] @raise [ArgumentError] Unless passed a Numeric value. @return [void]

# File lib/eddy/models/element/r.rb, line 33
def value=(arg)
  if arg == :skip
    @val = :skip
    return
  end
  if arg.nil?()
    @val = arg
    return
  end
  raise Eddy::Errors::TypeValidationError.new(element: self, arg: arg) unless arg.is_a?(Numeric)
  @val = arg
end