Class: Stupidedi::Versions::Common::ElementTypes::FixnumVal

Inherits:
Stupidedi::Values::SimpleElementVal show all
Defined in:
lib/stupidedi/versions/common/element_types/nn.rb

Overview

See Also:

  • B.1.1.3.1.1 Numeric

Direct Known Subclasses

Invalid, Valid

Defined Under Namespace

Classes: Empty, Invalid, NonEmpty, Valid

Instance Attribute Summary

Attributes inherited from Stupidedi::Values::SimpleElementVal

#position, #usage

Constructors collapse

Instance Method Summary collapse

Methods inherited from Stupidedi::Values::SimpleElementVal

#allowed?, #component?, #copy, #date?, #id?, #initialize, #leaf?, #simple?, #string?, #time?, #to_s, #to_x12, #valid?

Methods inherited from Stupidedi::Values::AbstractElementVal

#element?, #size

Methods inherited from Stupidedi::Values::AbstractVal

#blank?, #characters, #component?, #composite?, #definition, #descriptor, #element?, #empty?, #functional_group?, #interchange?, #invalid?, #leaf?, #loop?, #present?, #repeated?, #segment?, #separator?, #simple?, #size, #table?, #transaction_set?, #transmission?, #valid?

Methods included from Color

ansi, #ansi

Methods included from Inspect

#inspect

Constructor Details

This class inherits a constructor from Stupidedi::Values::SimpleElementVal

Class Method Details

.empty(usage, position) ⇒ FixnumVal

Returns:



279
280
281
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 279

def empty(usage, position)
  self::Empty.new(usage, position)
end

.value(object, usage, position) ⇒ FixnumVal

Returns:



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 284

def value(object, usage, position)
  if object.is_a?(FixnumVal)
    object#.copy(:usage => usage, :position => position)
  elsif object.blank?
    self::Empty.new(usage, position)
  elsif object.is_a?(String)
    # The number of fractional digits is implied by usage.precision
    factor = 10 ** usage.definition.precision
    self::NonEmpty.new(object.to_d / factor, usage, position)
  else
    self::NonEmpty.new(object.to_d, usage, position)
  end
rescue ArgumentError
  self::Invalid.new(object, usage, position)
end

Instance Method Details

#numeric?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 44

def numeric?
  true
end

#too_long?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 48

def too_long?
  false
end

#too_short?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/stupidedi/versions/common/element_types/nn.rb', line 52

def too_short?
  false
end