lib/eddy/models/element/r.rb in eddy-0.6.0 vs lib/eddy/models/element/r.rb in eddy-0.7.0
- old
+ new
@@ -25,50 +25,53 @@
self.req = req
self.ref = ref
self.value = val
end
- # @return [String]
- def value()
- if @val.nil?
- case self.req
- when "M" then raise Eddy::Errors::ElementNilValueError.new(element: self)
- when "O", "C" then return ""
- else raise Eddy::Errors::Error, "Invalid req value: #{self.req}"
- end
- end
- return process(@val)
- end
-
# @param arg [Numeric]
# @raise [ArgumentError] Unless passed a Numeric value.
# @return [void]
def value=(arg)
- if arg.nil?
+ 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
- # Stringify a float value and trim to the element's `max` attribute.
+ # @return [String]
+ def value()
+ return super()
+ end
+
+ # @return [String]
+ def process_value()
+ return self.class.process_value(@val, self.max)
+ end
+
+ # Stringify a numeric value and trim it to `max`.
#
# TODO: Use `sprintf` here?
#
# See:
#
# - [Ruby class types and case statements (Stack Overflow)](https://stackoverflow.com/questions/3908380/ruby-class-types-and-case-statements)
# - [Numbers and Class Hierarchy in Ruby (Medium)](https://medium.com/rubyinside/numbers-and-class-hierarchy-in-ruby-8c93c4749316)
#
# @param val [Numeric]
+ # @param max [Integer]
# @return [String]
- def process(val)
+ def self.process_value(val, max)
case val
when Integer
- return val.to_s.slice(0..self.max)
+ return val.to_s.slice(0..max)
when Float
- return val.to_s.slice(0..(self.max + 1))
+ return val.to_s.slice(0..(max + 1))
when Complex
# TODO: Handle case
raise NotImplementedError
when Rational
# TODO: Handle case