lib/eddy/models/element/base.rb in eddy-0.6.0 vs lib/eddy/models/element/base.rb in eddy-0.7.0
- old
+ new
@@ -1,9 +1,10 @@
module Eddy
module Models
module Element
# Base class for EDI Data Element types.
+ # @abstract
class Base
# Positive number under 1688, or I01-I64
# @return [String]
attr_reader :id
@@ -22,24 +23,50 @@
attr_reader :max
# String used to identify a data element within a Segment.
# @return [String]
attr_accessor :ref
- # # @return [void]
- # def initialize(**kwargs)
+ # @return [void]
+ def initialize()
+ @val = nil
+ @req = nil
+ end
- # end
+ # @note Classes inheriting from `Eddy::Models::Element::Base` must override the method `#value=`.
+ # @return [void]
+ def value=(*)
+ raise NotImplementedError, "Classes inheriting from `Eddy::Models::Element::Base` must override the method `#value=`"
+ end
- # @note Classes inheriting from `Eddy::Models::Element::Base` must define the method `value`.
+ # @note Classes inheriting from `Eddy::Models::Element::Base` must override the method `#value`.
+ # @return [Object]
+ def value()
+ if @val == :skip
+ return ""
+ elsif @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 self.process_value()
+ end
+
+ # Return a valid EDI string representation of `@value`.
+ #
+ # @note Classes inheriting from `Eddy::Models::Element::Base` must override the method `#process_value`.
# @return [void]
- def value(*)
- raise NotImplementedError, "Classes inheriting from `Eddy::Models::Element::Base` must define a `value` method."
+ def process_value(*)
+ raise NotImplementedError, "Classes inheriting from `Eddy::Models::Element::Base` must override the method `#process_value`"
end
- # @note Classes inheriting from `Eddy::Models::Element::Base` must define the method `value=`.
+ # Return a valid EDI string representation of `@value`.
+ #
+ # @note Classes inheriting from `Eddy::Models::Element::Base` must override the class the method `process_value`.
# @return [void]
- def value=(*)
- raise NotImplementedError, "Classes inheriting from `Eddy::Models::Element::Base` must define a `value=` method."
+ def self.process_value(*)
+ raise NotImplementedError, "Classes inheriting from `Eddy::Models::Element::Base` must override the class the method `process_value`"
end
# Indicates whether the value must be present in its segment.
#
# | code | description | official |