Class: Eddy::Models::Element::R
- Defined in:
- lib/eddy/models/element/r.rb
Overview
Decimal Numeric (decimal points must be transmitted if used).
Direct Known Subclasses
Elements::E183, Elements::E212, Elements::E330, Elements::E347, Elements::E358, Elements::E380, Elements::E382, Elements::E646, Elements::E649, Elements::E782, Elements::E81
Instance Attribute Summary
Attributes inherited from Base
#description, #id, #max, #min, #name, #ref, #type
Class Method Summary collapse
-
.process_value(val, max) ⇒ String
Stringify a numeric value and trim it to
max
.
Instance Method Summary collapse
- #initialize(min:, max:, req: nil, ref: nil, val: nil) ⇒ void constructor
- #process_value ⇒ String
- #value ⇒ String
- #value=(arg) ⇒ void
Methods inherited from Base
Constructor Details
#initialize(min:, max:, req: nil, ref: nil, val: nil) ⇒ void
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:
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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 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_value ⇒ 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 |
#value ⇒ 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.
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 |