Class: Stupidedi::Versions::Common::ElementTypes::FixnumVal::NonEmpty
- Inherits:
-
Valid
- Object
- Stupidedi::Values::AbstractVal
- Stupidedi::Values::AbstractElementVal
- Stupidedi::Values::SimpleElementVal
- Stupidedi::Versions::Common::ElementTypes::FixnumVal
- Valid
- Stupidedi::Versions::Common::ElementTypes::FixnumVal::NonEmpty
- Extended by:
- Operators::Binary, Operators::Relational, Operators::Unary
- Defined in:
- lib/stupidedi/versions/common/element_types/nn.rb
Overview
Non-empty numeric value. Shouldn't be directly instantiated -- instead, use the value constructors.
Instance Attribute Summary collapse
- #value ⇒ BigDecimal readonly
Attributes inherited from Stupidedi::Values::SimpleElementVal
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(value, usage, position) ⇒ NonEmpty
constructor
A new instance of NonEmpty.
-
#inspect ⇒ String
:nocov:.
- #to_s ⇒ String
- #to_x12(truncate = true) ⇒ String
- #too_long? ⇒ Boolean
Methods included from Operators::Binary
Methods included from Operators::Unary
Methods included from Operators::Relational
Methods inherited from Valid
#==, #coerce, #copy, #map, #valid?
Methods inherited from Stupidedi::Versions::Common::ElementTypes::FixnumVal
empty, #numeric?, #too_short?, value
Methods inherited from Stupidedi::Values::SimpleElementVal
#allowed?, #component?, #copy, #date?, #id?, #leaf?, #numeric?, #simple?, #string?, #time?, #too_short?, #valid?
Methods inherited from Stupidedi::Values::AbstractElementVal
Methods inherited from Stupidedi::Values::AbstractVal
#blank?, #characters, #component?, #composite?, #definition, #descriptor, #element?, #functional_group?, #interchange?, #invalid?, #leaf?, #loop?, #present?, #repeated?, #segment?, #separator?, #simple?, #size, #table?, #transaction_set?, #transmission?, #valid?
Methods included from Color
Constructor Details
#initialize(value, usage, position) ⇒ NonEmpty
Returns a new instance of NonEmpty.
214 215 216 217 |
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 214 def initialize(value, usage, position) @value = value super(usage, position) end |
Instance Attribute Details
#value ⇒ BigDecimal (readonly)
210 211 212 |
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 210 def value @value end |
Instance Method Details
#empty? ⇒ Boolean
219 220 221 |
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 219 def empty? false end |
#inspect ⇒ String
:nocov:
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 232 def inspect id = definition.bind do |d| "[#{"% 5s" % d.id}: #{d.name}]".bind do |s| if usage.forbidden? ansi.forbidden(s) elsif usage.required? ansi.required(s) else ansi.optional(s) end end end ansi.element("Nn.value#{id}") + "(#{@value.to_s("F").gsub(/\.0+$/, "")})" end |
#to_s ⇒ String
250 251 252 253 |
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 250 def to_s # The number of fractional digits is implied by usage.precision @value.to_s("F").gsub(/\.0+$/, "") end |
#to_x12(truncate = true) ⇒ String
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 256 def to_x12(truncate = true) nn = (@value * (10 ** definition.precision)).to_i sign = (nn < 0) ? "-" : "" # Leading zeros must be suppressed unless necessary to satisfy a # minimum length requirement if truncate sign = sign + nn.abs.to_s. take(definition.max_length). rjust(definition.min_length, "0") else sign = sign + nn.abs.to_s. rjust(definition.min_length, "0") end end |
#too_long? ⇒ Boolean
223 224 225 226 227 228 |
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 223 def too_long? nn = (@value * (10 ** definition.precision)).to_i # The length of a numeric type does not include an optional sign definition.max_length < nn.abs.to_s.length end |