Class: Eddy::Models::Element::R

Inherits:
Base
  • Object
show all
Defined in:
lib/eddy/models/element/r.rb

Overview

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

Instance Attribute Summary

Attributes inherited from Base

#description, #id, #max, #min, #name, #ref, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#doc_comment, #req, #req=

Constructor Details

#initialize(min:, max:, req: nil, ref: nil, val: nil) ⇒ void

Parameters:

  • min (Integer)
  • max (Integer)
  • req (String) (defaults to: nil)

    (nil)

  • ref (String) (defaults to: nil)

    (nil)

  • val (Numeric) (defaults to: nil)

    (nil)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

Class Method Details

.process_value(val, max) ⇒ String

Stringify a numeric value and trim it to max.

TODO: Use sprintf here?

See:

Parameters:

  • val (Numeric)
  • max (Integer)

Returns:

  • (String)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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

Instance Method Details

#process_valueString

Returns:

  • (String)


52
53
54
# File 'lib/eddy/models/element/r.rb', line 52

def process_value()
  return self.class.process_value(@val, self.max)
end

#valueString

Returns:

  • (String)


47
48
49
# File 'lib/eddy/models/element/r.rb', line 47

def value()
  return super()
end

#value=(arg) ⇒ void

This method returns an undefined value.

Parameters:

  • arg (Numeric)

Raises:

  • (ArgumentError)

    Unless passed a Numeric value.



33
34
35
36
37
38
39
40
41
42
43
44
# 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